[][src]Struct zerogc::Gc

#[repr(C)]pub struct Gc<'gc, T: GcSafe + ?Sized + 'gc, Id: CollectorId> { /* fields omitted */ }

A garbage collected pointer to a value.

This is the equivalent of a garbage collected smart-pointer. It's so smart, you can even coerce it to a reference bound to the lifetime of the GarbageCollectorRef. However, all those references are invalidated by the borrow checker as soon as your reference to the collector reaches a safepoint. The objects can only survive garbage collection if they live in this smart-pointer.

The smart pointer is simply a guarantee to the garbage collector that this points to a garbage collected object with the correct header, and not some arbitrary bits that you've decided to heap allocate.

Implementations

impl<'gc, T: GcSafe + ?Sized + 'gc, Id: CollectorId> Gc<'gc, T, Id>[src]

pub unsafe fn from_raw(id: Id, value: NonNull<T>) -> Self[src]

Create a GC pointer from a raw ID/pointer pair

Safety

Undefined behavior if the underlying pointer is not valid and associated with the collector corresponding to the id.

pub fn value(&self) -> &'gc T

Notable traits for &'_ mut R

impl<'_, R> Read for &'_ mut R where
    R: Read + ?Sized
impl<'_, W> Write for &'_ mut W where
    W: Write + ?Sized
impl<'_, F> Future for &'_ mut F where
    F: Unpin + Future + ?Sized
type Output = <F as Future>::Output;impl<'_, I> Iterator for &'_ mut I where
    I: Iterator + ?Sized
type Item = <I as Iterator>::Item;
[src]

The value of the underlying pointer

pub unsafe fn as_raw_ptr(&self) -> *mut T[src]

Cast this reference to a raw pointer

Safety

It's undefined behavior to mutate the value. The pointer is only valid as long as the reference is.

pub fn create_handle<'a>(
    &self
) -> <Id::System as GcHandleSystem<'gc, 'a, T>>::Handle where
    Id::System: GcHandleSystem<'gc, 'a, T>,
    T: GcErase<'a, Id> + 'a,
    <T as GcErase<'a, Id>>::Erased: GcSafe + 'a, 
[src]

Create a handle to this object, which can be used without a context

pub fn system(&self) -> &Id::System[src]

Get a reference to the system

Safety

This is based on the assumption that a GcSystem must outlive all of the pointers it owns. Although it could be restricted to the lifetime of the CollectorId (in theory that may have an internal pointer) it will still live for '&self'.

pub fn collector_id(&self) -> Id[src]

Get a copy of the collector's id

The underlying collector it points to is not necessarily always valid

Trait Implementations

impl<'gc, T: GcSafe + ?Sized + 'gc, Id: CollectorId> Clone for Gc<'gc, T, Id>[src]

impl<'gc, T: GcSafe + ?Sized + 'gc, Id: CollectorId> Copy for Gc<'gc, T, Id>[src]

impl<'gc, T: GcSafe + Debug + 'gc, Id: CollectorId> Debug for Gc<'gc, T, Id>[src]

impl<'gc, T: GcSafe + 'gc, Id: CollectorId> Deref for Gc<'gc, T, Id>[src]

type Target = &'gc T

The resulting type after dereferencing.

impl<'gc, T: GcSafe + Eq + 'gc, Id: CollectorId> Eq for Gc<'gc, T, Id>[src]

impl<'gc, O, V, Id> GcDirectBarrier<'gc, Gc<'gc, O, Id>> for Gc<'gc, V, Id> where
    O: GcSafe + 'gc,
    V: GcSafe + 'gc,
    Id: CollectorId
[src]

impl<'gc, 'a, T, Id> GcErase<'a, Id> for Gc<'gc, T, Id> where
    T: GcSafe + GcErase<'a, Id>,
    <T as GcErase<'a, Id>>::Erased: GcSafe,
    Id: CollectorId
[src]

type Erased = Gc<'a, <T as GcErase<'a, Id>>::Erased, Id>

This type with all garbage collected lifetimes changed to 'static (or erased) Read more

impl<'gc, 'new_gc, T, Id> GcRebrand<'new_gc, Id> for Gc<'gc, T, Id> where
    T: GcSafe + GcRebrand<'new_gc, Id>,
    <T as GcRebrand<'new_gc, Id>>::Branded: GcSafe,
    Id: CollectorId
[src]

Rebrand

type Branded = Gc<'new_gc, <T as GcRebrand<'new_gc, Id>>::Branded, Id>

This type with all garbage collected lifetimes changed to 'new_gc Read more

impl<'gc, T: GcSafe + 'gc, Id: CollectorId> GcSafe for Gc<'gc, T, Id>[src]

Double-indirection is completely safe

impl<'gc, T: GcSafe + Hash + 'gc, Id: CollectorId> Hash for Gc<'gc, T, Id>[src]

impl<'gc, T: GcSafe + PartialEq + 'gc, Id: CollectorId> PartialEq<Gc<'gc, T, Id>> for Gc<'gc, T, Id>[src]

impl<'gc, T: GcSafe + PartialEq + 'gc, Id: CollectorId> PartialEq<T> for Gc<'gc, T, Id>[src]

impl<'gc, T: ?Sized, Id> Send for Gc<'gc, T, Id> where
    T: GcSafe + Sync,
    Id: CollectorId + Sync
[src]

In order to send references between threads, the underlying type must be sync.

This is the same reason that Arc<T>: Send requires T: Sync

impl<'gc, T: ?Sized, Id> Sync for Gc<'gc, T, Id> where
    T: GcSafe + Sync,
    Id: CollectorId + Sync
[src]

If the underlying type is Sync, it's safe to share garbage collected references between threads.

The safety of the collector itself depends on whether CollectorId is Sync. If it is, the whole garbage collection implenentation should be as well.

impl<'gc, T: GcSafe + 'gc, Id: CollectorId> Trace for Gc<'gc, T, Id>[src]

Auto Trait Implementations

impl<'gc, T: ?Sized, Id> RefUnwindSafe for Gc<'gc, T, Id> where
    Id: RefUnwindSafe,
    T: RefUnwindSafe
[src]

impl<'gc, T: ?Sized, Id> Unpin for Gc<'gc, T, Id> where
    Id: Unpin
[src]

impl<'gc, T: ?Sized, Id> UnwindSafe for Gc<'gc, T, Id> where
    Id: UnwindSafe,
    T: RefUnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.