Struct gc::GcCell

source ·
pub struct GcCell<T: ?Sized + 'static> { /* private fields */ }
Expand description

A mutable memory location with dynamically checked borrow rules that can be used inside of a garbage-collected pointer.

This object is a RefCell that can be used inside of a Gc<T>.

Implementations§

source§

impl<T> GcCell<T>

source

pub fn new(value: T) -> Self

Creates a new GcCell containing value.

source

pub fn into_inner(self) -> T

Consumes the GcCell, returning the wrapped value.

source§

impl<T: ?Sized> GcCell<T>

source

pub fn borrow(&self) -> GcCellRef<'_, T>

Immutably borrows the wrapped value.

The borrow lasts until the returned GcCellRef exits scope. Multiple immutable borrows can be taken out at the same time.

Panics

Panics if the value is currently mutably borrowed.

source§

impl<T: Trace + ?Sized> GcCell<T>

source

pub fn borrow_mut(&self) -> GcCellRefMut<'_, T>

Mutably borrows the wrapped value.

The borrow lasts until the returned GcCellRefMut exits scope. The value cannot be borrowed while this borrow is active.

Panics

Panics if the value is currently borrowed.

source§

impl<T: ?Sized> GcCell<T>

source

pub fn try_borrow(&self) -> Result<GcCellRef<'_, T>, BorrowError>

Immutably borrows the wrapped value, returning an error if the value is currently mutably borrowed.

The borrow lasts until the returned GcCellRef exits scope. Multiple immutable borrows can be taken out at the same time.

This is the non-panicking variant of borrow.

Examples
use gc::GcCell;

let c = GcCell::new(5);

{
    let m = c.borrow_mut();
    assert!(c.try_borrow().is_err());
}

{
    let m = c.borrow();
    assert!(c.try_borrow().is_ok());
}
source§

impl<T: Trace + ?Sized> GcCell<T>

source

pub fn try_borrow_mut(&self) -> Result<GcCellRefMut<'_, T>, BorrowMutError>

Mutably borrows the wrapped value, returning an error if the value is currently borrowed.

The borrow lasts until the returned GcCellRefMut exits scope. The value cannot be borrowed while this borrow is active.

This is the non-panicking variant of borrow_mut.

Examples
use gc::GcCell;

let c = GcCell::new(5);

{
    let m = c.borrow();
    assert!(c.try_borrow_mut().is_err());
}

assert!(c.try_borrow_mut().is_ok());

Trait Implementations§

source§

impl<T: Clone> Clone for GcCell<T>

source§

fn clone(&self) -> Self

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<T: ?Sized + Debug> Debug for GcCell<T>

source§

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

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

impl<T: Default> Default for GcCell<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T: ?Sized> Finalize for GcCell<T>

source§

impl<T: ?Sized + Ord> Ord for GcCell<T>

source§

fn cmp(&self, other: &GcCell<T>) -> Ordering

This method returns an Ordering between self and other. Read more
source§

impl<T: ?Sized + PartialEq> PartialEq<GcCell<T>> for GcCell<T>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: ?Sized + PartialOrd> PartialOrd<GcCell<T>> for GcCell<T>

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T: Trace + ?Sized> Trace for GcCell<T>

source§

unsafe fn trace(&self)

Marks all contained Gcs.
source§

unsafe fn root(&self)

Increments the root-count of all contained Gcs.
source§

unsafe fn unroot(&self)

Decrements the root-count of all contained Gcs.
source§

fn finalize_glue(&self)

Runs Finalize::finalize() on this object and all contained subobjects
source§

impl<T: ?Sized + Eq> Eq for GcCell<T>

source§

impl<T: ?Sized + Send> Send for GcCell<T>

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for GcCell<T>

§

impl<T> !Sync for GcCell<T>

§

impl<T: ?Sized> Unpin for GcCell<T>where T: Unpin,

§

impl<T: ?Sized> UnwindSafe for GcCell<T>where T: UnwindSafe,

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