[−][src]Struct zerogc::Gc
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
[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(&self) -> <Id::System as GcHandleSystem<'gc, T>>::Handle where
Id::System: GcHandleSystem<'gc, T>,
T: GcBrand<'static, Id>,
<T as GcBrand<'static, Id>>::Branded: GcSafe,
[src]
Id::System: GcHandleSystem<'gc, T>,
T: GcBrand<'static, Id>,
<T as GcBrand<'static, Id>>::Branded: GcSafe,
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]
pub fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[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.
pub fn deref(&self) -> &Self::Target
[src]
impl<'gc, T: GcSafe + Eq + 'gc, Id: CollectorId> Eq for Gc<'gc, T, Id>
[src]
impl<'gc, 'new_gc, T, Id> GcBrand<'new_gc, Id> for Gc<'gc, T, Id> where
T: GcSafe + GcBrand<'new_gc, Id>,
T::Branded: GcSafe,
Id: CollectorId,
[src]
T: GcSafe + GcBrand<'new_gc, Id>,
T::Branded: GcSafe,
Id: CollectorId,
Rebrand
type Branded = Gc<'new_gc, <T as GcBrand<'new_gc, Id>>::Branded, Id>
This type with all garbage collected lifetimes
changed to 'new_gc
Read more
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]
O: GcSafe + 'gc,
V: GcSafe + 'gc,
Id: CollectorId,
pub unsafe fn write_barrier(&self, owner: &Gc<'gc, O, Id>, field_offset: usize)
[src]
impl<'gc, T: GcSafe + 'gc, Id: CollectorId> GcSafe for Gc<'gc, T, Id>
[src]
Double-indirection is completely safe
pub const NEEDS_DROP: bool
[src]
impl<'gc, T: GcSafe + Hash + 'gc, Id: CollectorId> Hash for Gc<'gc, T, Id>
[src]
pub fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'gc, T: GcSafe + PartialEq + 'gc, Id: CollectorId> PartialEq<Gc<'gc, T, Id>> for Gc<'gc, T, Id>
[src]
pub fn eq(&self, other: &Self) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[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]
T: GcSafe + Sync,
Id: CollectorId + Sync,
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]
T: GcSafe + Sync,
Id: CollectorId + Sync,
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]
Id: RefUnwindSafe,
T: RefUnwindSafe,
impl<'gc, T: ?Sized, Id> Unpin for Gc<'gc, T, Id> where
Id: Unpin,
[src]
Id: Unpin,
impl<'gc, T: ?Sized, Id> UnwindSafe for Gc<'gc, T, Id> where
Id: UnwindSafe,
T: RefUnwindSafe,
[src]
Id: UnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,