pub struct LCell<'id, T: ?Sized> { /* private fields */ }
Expand description
Cell whose contents are owned (for borrowing purposes) by a
LCellOwner
.
To borrow from this cell, use the borrowing calls on the
LCellOwner
instance that owns it, i.e. that shares the same
Rust lifetime.
See also crate documentation.
Implementations§
Source§impl<'id, T> LCell<'id, T>
impl<'id, T> LCell<'id, T>
Sourcepub fn new(value: T) -> LCell<'id, T>
pub fn new(value: T) -> LCell<'id, T>
Create a new LCell
. The owner of this cell is inferred by
Rust from the context. So the owner lifetime is whatever
lifetime is required by the first use of the new LCell
.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Destroy the cell and return the contained value
Safety: Since this consumes the cell, there can be no other references to the cell or the data at this point.
Source§impl<'id, T: ?Sized> LCell<'id, T>
impl<'id, T: ?Sized> LCell<'id, T>
Sourcepub fn ro<'a>(&'a self, owner: &'a LCellOwner<'id>) -> &'a T
pub fn ro<'a>(&'a self, owner: &'a LCellOwner<'id>) -> &'a T
Borrow contents of this cell immutably (read-only). Many
LCell
instances can be borrowed immutably at the same time
from the same owner.
Sourcepub fn rw<'a>(&'a self, owner: &'a mut LCellOwner<'id>) -> &'a mut T
pub fn rw<'a>(&'a self, owner: &'a mut LCellOwner<'id>) -> &'a mut T
Borrow contents of this cell mutably (read-write). Only one
LCell
at a time can be borrowed from the owner using this
call. The returned reference must go out of scope before
another can be borrowed. To mutably borrow from two or three
cells at the same time, see LCellOwner::rw2
or
LCellOwner::rw3
.
Sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Returns a mutable reference to the underlying data
Note that this is only useful at the beginning-of-life or
end-of-life of the cell when you have exclusive access to it.
Normally you’d use LCell::rw
or LCellOwner::rw
to get
a mutable reference to the contents of the cell.
Safety: This call borrows LCell
mutably which guarantees
that we possess the only reference. This means that there can
be no active borrows of other forms, even ones obtained using
an immutable reference.