Macro netsblox_vm::gc::Rootable

source ·
macro_rules! Rootable {
    ($gc:lifetime => $root:ty) => { ... };
    ($root:ty) => { ... };
}
Expand description

A convenience macro for quickly creating type that implements Rootable.

The macro takes a single argument, which should be a generic type with elided lifetimes. When used as a root object, every instances of the elided lifetime will be replaced with the branding lifetime.

#[derive(Collect)]
#[collect(no_drop)]
struct MyRoot<'gc> {
    ptr: Gc<'gc, i32>,
}

type MyArena = Arena<Rootable![MyRoot<'_>]>;

// If desired, the branding lifetime can also be explicitely named:
type MyArena2 = Arena<Rootable!['gc => MyRoot<'gc>]>;

The macro can also be used to create implementations of Rootable that use other generic parameters, though in complex cases it may be better to implement Rootable directly.

#[derive(Collect)]
#[collect(no_drop)]
struct MyGenericRoot<'gc, T: 'static> {
    ptr: Gc<'gc, StaticCollect<T>>,
}

type MyGenericArena<T> = Arena<Rootable![MyGenericRoot<'_, T>]>;