pub struct DynamicRoot<R: for<'gc> Rootable<'gc>> { /* private fields */ }
Expand description
An unbranded, reference-counted handle to a GC root held in some DynamicRootSet
.
A DynamicRoot
can freely be stored outside GC arenas; in exchange, all accesses to the held
object must go through the DynamicRootSet
from which it was created.
This handle is cheaply clonable: all clones will refer to the same object, which will be dropped when the last surviving handle goes out of scope.
Implementations§
Source§impl<R: for<'gc> Rootable<'gc>> DynamicRoot<R>
impl<R: for<'gc> Rootable<'gc>> DynamicRoot<R>
Sourcepub fn as_ptr<'gc>(&self) -> *const Root<'gc, R>
pub fn as_ptr<'gc>(&self) -> *const Root<'gc, R>
Get a pointer to the held object.
§Safety
The pointer will never be dangling as long as at least one DynamicRoot
is alive, but
using the object behind this pointer is extremely dangerous.
Firstly, the 'gc
lifetime returned here is unbound, so it is meaningless and can allow
improper mixing of objects across arenas.
Secondly, though the pointer to the object itself will not be dangling, any garbage
collected pointers the object holds will be dangling if the DynamicRootSet
backing
this root has been collected.