Class in gc compiler

Root

class Root<T>
Import
use gc::{Root};
Source: compiler/src/builtin_docs/gc.hy

A strong pin that keeps a value alive, made by root.

While the Root itself is reachable, the garbage collector keeps its value alive, even when nothing else refers to it. The usual use is FFI: pin a Coil buffer or callback before handing its address to C code that keeps it. Read the value with get, release it with unroot. A Root cannot be sent to another thread.

Examples#

use gc::{root, get, Root};
use tests::assert;
let pin: Root<Vec<int>> = root(Vec::from([1, 2, 3]));
let n = match get(pin) {
    Option::Some(v) => v.len(),
    Option::None => 0,
};
assert!(n == 3);

See also#

↑ ↓ navigate ↵ open