pub unsafe trait GcSimpleAlloc<'gc, T: GcSafe + 'gc>: GcContext + 'gc {
// Required method
fn alloc(&'gc self, value: T) -> Gc<'gc, T, Self::Id>;
}
Expand description
A simple interface to allocating from a GcContext.
Some garbage collectors implement more complex interfaces, so implementing this is optional
Required Methods§
Sourcefn alloc(&'gc self, value: T) -> Gc<'gc, T, Self::Id>
fn alloc(&'gc self, value: T) -> Gc<'gc, T, Self::Id>
Allocate the specified object in this garbage collector, binding it to the lifetime of this collector.
The object will never be collected until the next safepoint, which is considered a mutation by the borrow checker and will be statically checked. Therefore, we can statically guarantee the pointers will survive until the next safepoint.
See safepoint!
docs on how to properly invoke a safepoint
and transfer values across it.
This gives a immutable reference to the resulting object.
Once allocated, the object can only be correctly modified with a GcCell
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.