pub struct DynamicRoot<R: for<'gc> Rootable<'gc>> { /* private fields */ }Expand description
Handle to a Gc pointer held inside a DynamicRootSet which is 'static and can be held
outside of the arena.
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.
This returns Gc::as_ptr for the Gc provided when the DynamicRoot is stashed.
§Safety
It is possible to use this to reconstruct the original Gc pointer by calling the unsafe
Gc::from_ptr, but this is incredibly dangerous!
First, if the DynamicRootSet in which the DynamicRoot was stashed has been collected,
then either the returned pointer or other transitive Gc pointers objects may be dangling.
The parent DynamicRootSet must still be uncollected in order to do this soundly.
Second, the 'gc lifetime returned here is unbound, so it is meaningless and can allow
improper mixing of objects across arenas. The returned 'gc lifetime must be bound to only
the arena that holds the parent DynamicRootSet.