pub struct Cell<T>where
T: 'static + ?Sized,{ /* 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
sourceimpl<T> GcCell<T>where
T: Trace,
impl<T> GcCell<T>where
T: Trace,
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes the GcCell
, returning the wrapped value.
sourceimpl<T> GcCell<T>where
T: Trace + ?Sized,
impl<T> GcCell<T>where
T: Trace + ?Sized,
sourcepub fn borrow(&self) -> GcCellRef<'_, T>
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.
sourcepub fn borrow_mut(&self) -> GcCellRefMut<'_, T, T>
pub fn borrow_mut(&self) -> GcCellRefMut<'_, T, 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.
sourcepub fn try_borrow(&self) -> Result<GcCellRef<'_, T>, BorrowError>
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());
}
sourcepub fn try_borrow_mut(&self) -> Result<GcCellRefMut<'_, T, T>, BorrowMutError>
pub fn try_borrow_mut(&self) -> Result<GcCellRefMut<'_, T, 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
sourceimpl<T> PartialEq<GcCell<T>> for GcCell<T>where
T: Trace + PartialEq<T> + ?Sized,
impl<T> PartialEq<GcCell<T>> for GcCell<T>where
T: Trace + PartialEq<T> + ?Sized,
sourceimpl<T> PartialOrd<GcCell<T>> for GcCell<T>where
T: Trace + PartialOrd<T> + ?Sized,
impl<T> PartialOrd<GcCell<T>> for GcCell<T>where
T: Trace + PartialOrd<T> + ?Sized,
sourcefn partial_cmp(&self, other: &GcCell<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &GcCell<T>) -> Option<Ordering>
sourcefn le(&self, other: &GcCell<T>) -> bool
fn le(&self, other: &GcCell<T>) -> bool
self
and other
) and is used by the <=
operator. Read more