Function in gc compiler

get

fn get<T>(Root<T> pin) -> Option<T>
Import
use gc::{get};
Source: compiler/src/builtin_docs/gc.hy

Returns the pinned value, leaving the pin in place.

Returns None after unroot has released the pin.

Parameters#

NameType
pinRoot<T>

Returns#

Option<T>

Examples#

use gc::{root, get, unroot};
use tests::assert;
let pin = root(7);
assert!(match get(pin) { Option::Some(n) => n == 7, Option::None => false });
let _ = unroot(pin);
assert!(match get(pin) { Option::Some(_) => false, Option::None => true });

See also#

  • gc::unroot
  • root: Pins value so the garbage collector keeps it alive while the returned Root is reachable.
  • weak: Makes a handle to value that does not keep it alive.
  • upgrade: Returns the value while it is still alive, None once it was collected.
  • heap_bytes: Returns the size of the managed heap in bytes.
  • collect: Runs a full garbage collection now and returns the number of bytes freed.
↑ ↓ navigate ↵ open