Struct netsblox_vm::gc::Gc

source ·
pub struct Gc<'gc, T>where
    T: 'gc + ?Sized,{ /* private fields */ }
Expand description

A garbage collected pointer to a type T. Implements Copy, and is implemented as a plain machine pointer. You can only allocate Gc pointers through a &Mutation<'gc> inside an arena type, and through “generativity” such Gc pointers may not escape the arena they were born in or be stored inside TLS. This, combined with correct Collect implementations, means that Gc pointers will never be dangling and are always safe to access.

Implementations§

source§

impl<'gc, T> Gc<'gc, T>where T: Collect + 'gc,

source

pub fn new(mc: &Mutation<'gc>, t: T) -> Gc<'gc, T>

source§

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

source

pub unsafe fn cast<U>(this: Gc<'gc, T>) -> Gc<'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) -> Gc<'gc, T>

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

SAFETY: The provided pointer must have been obtained from Gc::as_ptr, and the pointer must not have been collected yet.

source§

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

source

pub fn unlock(self, mc: &Mutation<'gc>) -> &'gc <T as Unlock>::Unlocked

Shorthand for Gc::write(mc, self).unlock().

source§

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

source

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

Obtains a long-lived reference to the contents of this Gc.

Unlike AsRef or Deref, the returned reference isn’t bound to the Gc itself, and will stay valid for the entirety of the current arena callback.

source

pub fn downgrade(this: Gc<'gc, T>) -> GcWeak<'gc, T>

source

pub fn write(mc: &Mutation<'gc>, gc: Gc<'gc, T>) -> &'gc Write<T>

Triggers a write barrier on this Gc, allowing for further safe mutation.

source

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

source

pub fn as_ptr(gc: Gc<'gc, T>) -> *const T

source§

impl<'gc, T> Gc<'gc, Lock<T>>where T: Copy + 'gc,

source

pub fn get(self) -> T

source

pub fn set(self, mc: &Mutation<'gc>, t: T)

source§

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

source

pub fn borrow(self) -> Ref<'gc, T>

source

pub fn try_borrow(self) -> Result<Ref<'gc, T>, BorrowError>

source

pub fn borrow_mut(self, mc: &Mutation<'gc>) -> RefMut<'gc, T>

source

pub fn try_borrow_mut( self, mc: &Mutation<'gc> ) -> Result<RefMut<'gc, T>, BorrowMutError>

Trait Implementations§

source§

impl<'gc, T> AsRef<T> for Gc<'gc, T>where T: 'gc + ?Sized,

source§

fn as_ref(&self) -> &T

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

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

source§

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

Returns a copy 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 Gc<'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() -> boolwhere 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 Gc<'gc, T>where T: Debug + 'gc + ?Sized,

source§

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

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

impl<'gc, T> Deref for Gc<'gc, T>where T: 'gc + ?Sized,

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

impl<'gc, T> Display for Gc<'gc, T>where T: Display + 'gc + ?Sized,

source§

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

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

impl<'gc, C: CustomTypes<S>, S: System<C>> From<Gc<'gc, RefLock<Closure<'gc, C, S>>>> for Value<'gc, C, S>

source§

fn from(v: Gc<'gc, RefLock<Closure<'gc, C, S>>>) -> Self

Converts to this type from the input type.
source§

impl<'gc, C: CustomTypes<S>, S: System<C>> From<Gc<'gc, RefLock<Entity<'gc, C, S>>>> for Value<'gc, C, S>

source§

fn from(v: Gc<'gc, RefLock<Entity<'gc, C, S>>>) -> Self

Converts to this type from the input type.
source§

impl<'gc, C: CustomTypes<S>, S: System<C>> From<Gc<'gc, RefLock<VecDeque<Value<'gc, C, S>, Global>>>> for Value<'gc, C, S>

source§

fn from(v: Gc<'gc, RefLock<VecDeque<Value<'gc, C, S>>>>) -> Self

Converts to this type from the input type.
source§

impl<'gc, T> Pointer for Gc<'gc, T>where T: 'gc + ?Sized,

source§

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

Formats the value using the given formatter.
source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<'gc, T> !UnwindSafe for Gc<'gc, T>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

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

§

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
§

impl<T> Formattable for Twhere T: Deref, <T as Deref>::Target: Formattable,