Struct cell_family::Cell

source ·
#[repr(transparent)]
pub struct Cell<F: Family, T: ?Sized> { /* private fields */ }
Expand description

A cell whose mutability is determined through its CellOwner.

Example

let cell = Cell::new(vec![1, 2, 3]);
let mut owner = CellOwner::new();

cell.get_mut(&mut owner).push(4);

assert_eq!(cell.get(&owner), &[1, 2, 3, 4]);

Implementations§

Creates a new cell which wraps the given value, and whose value can be borrowed by a CellOwner.

Returns the inner value, consuming the cell.

Returns a reference to the underlying value of the cell, using the reference to the given CellOwner as a proof that this cell is not currently mutably borrowed.

Returns a reference to the underlying value of the cell without any checks.

Safety

When calling this method, you have to ensure that the current cell (and its underlying data) is not borrowed mutably for the entire lifetime of the returned reference.

Returns a reference to the underlying value of the cell, using the reference to the given CellOwner as a proof that this cell is not currently mutably borrowed.

Returns a mutable reference to the underlying value of the cell without any checks.

Safety

When calling this method, you have to ensure that the current cell (and its underlying data) is not borrowed anywhere else for the entire lifetime of the returned reference.

Clones the inner value and returns a Cell wrapping it.

Copies the inner value and returns a Cell wrapping it.

Trait Implementations§

Simple Debug implementation for Cell.

Example

let cell = Cell::new(vec![1, 2, 3]);
let owner = CellOwner::new();

assert_eq!(format!("{cell:?}"), "Cell { family: \"Family\", .. }");

drop(owner);

assert_eq!(format!("{cell:?}"), "Cell { family: \"Family\", value: [1, 2, 3] }");
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Converts to this type from the input type.
The result of Self::get_mut().
Returns a mutable reference to the requested value(s), returning None instead if any of them is not unique (i.e. referenced by two different cells). Read more
Same as Self::try_get_mut(), crashing on error.
The result of Self::get().
Returns a reference to the requested value(s).

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Converts to this type from the input type.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.