pub unsafe trait GcSimpleAlloc: GcContext {
    unsafe fn alloc_uninit<'gc, T>(&'gc self) -> *mut T
    where
        T: GcSafe<'gc, Self::Id>
;
unsafe fn alloc_uninit_slice<'gc, T>(&'gc self, len: usize) -> *mut T
    where
        T: GcSafe<'gc, Self::Id>
;
fn alloc_raw_vec_with_capacity<'gc, T>(
        &'gc self,
        capacity: usize
    ) -> <Self::Id as CollectorId>::RawVec
    where
        T: GcSafe<'gc, Self::Id>
; fn alloc<'gc, T>(&'gc self, value: T) -> Gc<'gc, T, Self::Id>
    where
        T: GcSafe<'gc, Self::Id>
, { ... }
fn alloc_str<'gc>(&'gc self, src: &str) -> GcString<'gc, Self::Id> { ... }
fn alloc_slice_copy<'gc, T>(
        &'gc self,
        src: &[T]
    ) -> GcArray<'gc, T, Self::Id>
    where
        T: GcSafe<'gc, Self::Id> + Copy
, { ... }
fn alloc_array_from_vec<'gc, T>(
        &'gc self,
        src: Vec<T>
    ) -> GcArray<'gc, T, Self::Id>
    where
        T: GcSafe<'gc, Self::Id>
, { ... }
unsafe fn alloc_slice_fill_with<'gc, T, F>(
        &'gc self,
        len: usize,
        func: F
    ) -> GcArray<'gc, T, Self::Id>
    where
        T: GcSafe<'gc, Self::Id>,
        F: FnMut(usize) -> T
, { ... }
fn alloc_slice_none<'gc, T>(
        &'gc self,
        len: usize
    ) -> GcArray<'gc, Option<T>, Self::Id>
    where
        T: GcSafe<'gc, Self::Id>
, { ... }
fn alloc_slice_fill_copy<'gc, T>(
        &'gc self,
        len: usize,
        val: T
    ) -> GcArray<'gc, T, Self::Id>
    where
        T: GcSafe<'gc, Self::Id> + Copy
, { ... }
fn alloc_vec<'gc, T>(&'gc self) -> GcVec<'gc, T, Self::Id>
    where
        T: GcSafe<'gc, Self::Id>
, { ... }
fn alloc_vec_with_capacity<'gc, T>(
        &'gc self,
        capacity: usize
    ) -> GcVec<'gc, T, Self::Id>
    where
        T: GcSafe<'gc, 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

Allocate room for a object in, but don’t finish initializing it.

Safety

The object must be initialized by the time the next collection rolls around, so that the collector can properly trace it

Allocate a slice with the specified length, whose memory is uninitialized

Safety

The slice MUST be initialized by the next safepoint. By the time the next collection rolls around, the collector will assume its entire contents are initialized.

In particular, the traditional way to implement a Vec is wrong. It is unsafe to leave the range of memory [len, capacity) uninitialized.

Create a new GcRawVec with the specified capacity and an implicit reference to this GcContext.

Provided methods

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

Allocate a GcString, copied from the specified source

Allocate a slice, copied from the specified input

Allocate an array, taking ownership of the values in the specified vec.

Allocate a slice by filling it with results from the specified closure.

The closure receives the target index as its only argument.

Safety

The closure must always succeed and never panic.

Otherwise, the gc may end up tracing the values even though they are uninitialized.

Allocate a slice of the specified length, initializing everything to None

Allocate a slice by repeatedly copying a single value.

Create a new GcVec with zero initial length, with an implicit reference to this GcContext.

Allocate a new GcVec with the specified capacity and an implicit reference to this GcContext

Implementors