Skip to main content

GcRef

Struct GcRef 

Source
pub struct GcRef<T: Trace + 'static>(pub Gc<T>);
Expand description

A GC-managed pointer to a Lua collectable object. Newtype over lua_gc::Gc<T> so callers preserve gc.0-shape access while the backend swaps under them.

Tuple Fields§

§0: Gc<T>

Implementations§

Source§

impl<T: Trace + 'static> GcRef<T>

Source

pub fn new(value: T) -> Self

Allocate a new GC-tracked value. If a HeapGuard is active (set by state.run() / pcall_k), the new allocation joins that heap’s allgc chain. Otherwise it allocates “uncollected” — leaks until process exit, same as the old Rc::new behavior.

Source

pub fn trace_obj(&self, m: &mut Marker)

Cycle-aware trace dispatch.

During D-0/D-1 (before a real Color::Gray flag is reachable from inside Trace impls), Marker::try_visit records the underlying allocation’s identity and short-circuits a second recursion. Once D-2 ships the in-header color flag, this helper collapses to m.mark(self.0).

Source§

impl<T: Trace + 'static> GcRef<T>

Source

pub fn ptr_eq(a: &Self, b: &Self) -> bool

Two GcRefs are identity-equal iff they point at the same box.

Source

pub fn identity(&self) -> usize

Identity as a usize — used as a HashMap key for “same object” tests.

Source

pub fn strong_count(&self) -> usize

Number of strong references. Phase D-1: always returns 1 (no refcount semantics). Real value once weak refs land in D-2.

Source

pub fn weak_count(&self) -> usize

Number of weak references. Phase D-1: always returns 0.

Source

pub fn downgrade(&self) -> GcWeak<T>

Get a weak handle. Phase D-1: GcWeak is a thin wrapper that always upgrades; real weak semantics arrive in D-2.

Trait Implementations§

Source§

impl<T: Trace + 'static> AsRef<T> for GcRef<T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Trace + 'static> Clone for GcRef<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Trace + 'static> Debug for GcRef<T>

Source§

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

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

impl<T: Trace + 'static> Deref for GcRef<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T: PartialEq + Trace + 'static> PartialEq for GcRef<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Trace + 'static> Trace for GcRef<T>

Forwarder for GcRef<T>. Now that GcRef wraps a real lua_gc::Gc<T> (D-1e), tracing must enqueue the box onto the gray queue via Marker::mark — that is what flips its header color from White to Gray and ultimately to Black during gray-queue drainage. The previous try_visit short-circuit was a Phase A-D-0 workaround for the Rc-backed handle (no header, no color), and produced a silent bug post-D-1e: every GC-tracked allocation stayed White and was freed in the sweep on the first collectgarbage(). Cycles are now handled natively by the heap’s gray-queue (Color::Gray check in mark makes re-visits idempotent).

Source§

fn trace(&self, m: &mut Marker)

Source§

impl<T: Trace + 'static> Copy for GcRef<T>

Auto Trait Implementations§

§

impl<T> Freeze for GcRef<T>

§

impl<T> !RefUnwindSafe for GcRef<T>

§

impl<T> !Send for GcRef<T>

§

impl<T> !Sync for GcRef<T>

§

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

§

impl<T> UnsafeUnpin for GcRef<T>

§

impl<T> !UnwindSafe for GcRef<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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.