Skip to main content

GcPtr

Struct GcPtr 

Source
pub struct GcPtr<T> { /* private fields */ }
Expand description

A pointer to a GC-managed object of type T.

The object is laid out in memory as:

[GcHeader (8 bytes)][T data (size bytes)]
                     ^--- GcPtr points here

GcPtr is Copy — no refcount manipulation. The GC is solely responsible for determining liveness and reclaiming memory.

Implementations§

Source§

impl<T> GcPtr<T>

Source

pub unsafe fn from_raw(ptr: *mut T) -> Self

Create a GcPtr from a raw pointer.

§Safety

The pointer must point to a valid T preceded by a GcHeader at ptr - 8.

Source

pub fn as_ptr(self) -> *mut T

Get the raw pointer to T.

Source

pub fn as_usize(self) -> usize

Get the raw pointer as usize (for NaN-boxing payload).

Source

pub fn header(self) -> &'static GcHeader

Get a reference to the GcHeader preceding this object.

Source

pub unsafe fn header_mut(self) -> &'static mut GcHeader

Get a mutable reference to the GcHeader preceding this object.

§Safety

Caller must ensure exclusive access to the header.

Source

pub unsafe fn deref_gc(self) -> &'static T

Dereference to get a reference to the managed object.

§Safety

The object must still be alive (not collected).

Source

pub unsafe fn deref_gc_mut(self) -> &'static mut T

Dereference to get a mutable reference to the managed object.

§Safety

The object must still be alive and caller must have exclusive access.

Source

pub fn with_mark_bit(self) -> Self

Set the inline mark bit (x86-64: use LAM if available, else no-op).

Source

pub fn clear_mark_bit(self) -> Self

Clear the inline mark bit (x86-64: use LAM if available, else no-op).

Source

pub fn has_mark_bit(self) -> bool

Check whether the inline mark bit is set (x86-64: use LAM if available).

Source

pub fn is_marked(self) -> bool

Check the mark state, combining inline pointer bits with the GcHeader side table for a definitive answer on any platform.

Returns true if either the inline mark bit is set (on HW-masking platforms) or the GcHeader color is Gray/Black.

Source

pub fn raw_ptr(self) -> *mut T

Strip all metadata bits from the pointer, returning the raw address.

Uses the detected masking mode to apply the correct mask.

Source

pub fn as_untyped(self) -> *mut u8

Convert to an untyped pointer for use in the root set / marker.

Source

pub unsafe fn from_untyped(ptr: *mut u8) -> Self

Create from an untyped pointer.

§Safety

The pointer must actually point to a valid T with GcHeader prefix.

Trait Implementations§

Source§

impl<T> Clone for GcPtr<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for GcPtr<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Pointer for GcPtr<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Copy for GcPtr<T>

Auto Trait Implementations§

§

impl<T> Freeze for GcPtr<T>

§

impl<T> RefUnwindSafe for GcPtr<T>
where T: RefUnwindSafe,

§

impl<T> !Send for GcPtr<T>

§

impl<T> !Sync for GcPtr<T>

§

impl<T> Unpin for GcPtr<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for GcPtr<T>

§

impl<T> UnwindSafe for GcPtr<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.