pub struct Root<T>where
T: Trace,{ /* private fields */ }
Expand description
A rooted reference to a GC-managed T
.
Root<T>
s prevent their referenced T
from being reclaimed during garbage
collections. This makes them suitable for holding references to GC-managed
objects across operations that can trigger GCs.
Root<T>
s are not suitable for referencing other GC-manged objects within
the definition of a GC-managed object. Doing this will effectively leak
everything transitively referenced from the Root<T>
. Instead, use
Gc<T>
for references to other GC-managed objects from within
a GC-managed object.
See also the docs for Gc<T>
for more examples of converting
between Root<T>
and Gc<T>
and when you want to use which type.
§Example: Creating a Root<T>
via Allocation
use safe_gc::{Gc, Heap, Root, Trace};
struct Node {
value: u32,
tail: Option<Gc<Node>>,
}
impl Trace for Node {
// ...
}
let mut heap = Heap::new();
// Allocating a new GC object in a heap returns a `Root<T>` reference.
let node: Root<Node> = heap.alloc(Node { value: 1234, tail: None });
Implementations§
Trait Implementations§
source§impl<T> PartialEq<Gc<T>> for Root<T>where
T: Trace,
impl<T> PartialEq<Gc<T>> for Root<T>where
T: Trace,
source§impl<T> PartialEq<Root<T>> for Gc<T>where
T: Trace,
impl<T> PartialEq<Root<T>> for Gc<T>where
T: Trace,
Auto Trait Implementations§
impl<T> Freeze for Root<T>
impl<T> !RefUnwindSafe for Root<T>
impl<T> !Send for Root<T>
impl<T> !Sync for Root<T>
impl<T> Unpin for Root<T>
impl<T> !UnwindSafe for Root<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)