Struct GcWeak

Source
pub struct GcWeak<'gc, T>
where T: 'gc + ?Sized,
{ /* private fields */ }

Implementations§

Source§

impl<'gc, T> GcWeak<'gc, T>
where T: 'gc + ?Sized,

Source

pub fn upgrade(self, mc: &Mutation<'gc>) -> Option<Gc<'gc, T>>

Source

pub fn is_dropped(self, _cc: &Collection) -> bool

During collection, return whether the value referenced by this GcWeak has already been dropped.

Source

pub fn is_dead(self, fc: &Finalization<'gc>) -> bool

Returns true when a pointer is dead during finalization.

This is a weaker condition than being dropped, as the pointer may still be valid. Being dead means that there were no strong pointers pointing to this weak pointer that were found by the marking phase, and if it is not already dropped, it will be dropped as soon as collection resumes.

If the pointer is still valid, it may be resurrected using GcWeak::upgrade or GcWeak::resurrect`.

NOTE: This returns true if the pointer was destined to be collected at the start of the current finalization callback. Resurrecting one pointer can transitively resurrect others, and this method does not reflect this from within the same finalization call! If transitive resurrection is important, you may have to carefully call finalize multiple times for one collection cycle with marking stages in-between, and in the precise order that you want.

Source

pub fn resurrect(self, fc: &Finalization<'gc>) -> Option<Gc<'gc, T>>

Manually marks a dead (but non-dropped) GcWeak as strongly reachable and keeps it alive.

This is similar to a write barrier in that it moves the collection phase back to Marking if it is not already there. All transitively held pointers from this will also be marked as reachable once marking resumes.

Returns the upgraded Gc pointer as a convenience. Whether or not the strong pointer is stored anywhere, the value and all transitively reachable values are still guaranteed to not be dropped this collection cycle.

Source

pub fn ptr_eq(this: GcWeak<'gc, T>, other: GcWeak<'gc, T>) -> bool

Returns true if two GcWeaks point to the same allocation.

Similarly to Rc::ptr_eq and Arc::ptr_eq, this function ignores the metadata of dyn pointers.

Source

pub fn as_ptr(self) -> *const T

Source§

impl<'gc, T> GcWeak<'gc, T>
where T: 'gc,

Source

pub unsafe fn cast<U>(this: GcWeak<'gc, T>) -> GcWeak<'gc, U>
where U: 'gc,

Cast the internal pointer to a different type.

SAFETY: It must be valid to dereference a *mut U that has come from casting a *mut T.

Source

pub unsafe fn from_ptr(ptr: *const T) -> GcWeak<'gc, T>

Retrieve a GcWeak from a raw pointer obtained from GcWeak::as_ptr

SAFETY: The provided pointer must have been obtained from GcWeak::as_ptr or Gc::as_ptr, and the pointer must not have been fully collected yet (it may be a dropped but valid weak pointer).

Trait Implementations§

Source§

impl<'gc, T> Clone for GcWeak<'gc, T>
where T: 'gc + ?Sized,

Source§

fn clone(&self) -> GcWeak<'gc, T>

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<'gc, T> Collect for GcWeak<'gc, T>
where T: 'gc + ?Sized,

Source§

fn trace(&self, cc: &Collection)

Must call Collect::trace on all held Gc pointers. If this type holds inner types that implement Collect, a valid implementation would simply call Collect::trace on all the held values to ensure this.
Source§

fn needs_trace() -> bool
where Self: Sized,

As an optimization, if this type can never hold a Gc pointer and trace is unnecessary to call, you may implement this method and return false. The default implementation returns true, signaling that Collect::trace must be called.
Source§

impl<'gc, T> Debug for GcWeak<'gc, T>
where T: 'gc + ?Sized,

Source§

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

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

impl<'gc, T> Copy for GcWeak<'gc, T>
where T: 'gc + ?Sized,

Auto Trait Implementations§

§

impl<'gc, T> Freeze for GcWeak<'gc, T>
where T: ?Sized,

§

impl<'gc, T> !RefUnwindSafe for GcWeak<'gc, T>

§

impl<'gc, T> !Send for GcWeak<'gc, T>

§

impl<'gc, T> !Sync for GcWeak<'gc, T>

§

impl<'gc, T> Unpin for GcWeak<'gc, T>
where T: ?Sized,

§

impl<'gc, T> !UnwindSafe for GcWeak<'gc, 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,