pub struct QCell<T: ?Sized> { /* private fields */ }
Expand description
Cell whose contents is owned (for borrowing purposes) by a
QCellOwner
, a QCellOwnerSeq
or a QCellOwnerPinned
.
To borrow from this cell, use the borrowing calls on the owner
instance that was used to create it. For QCellOwner
, there
are also convenience methods QCell::ro
and QCell::rw
. See
also crate documentation.
Implementations§
Source§impl<T> QCell<T>
impl<T> QCell<T>
Sourcepub fn new(id: impl Into<QCellOwnerID>, value: T) -> QCell<T>
pub fn new(id: impl Into<QCellOwnerID>, value: T) -> QCell<T>
Create a new QCell
owned for borrowing purposes by the
owner with the given QCellOwnerID
, or a type that can be
converted into a QCellOwnerID
, such as &owner
. So calls
will typically take the form QCell::new(&owner, value)
or
QCell::new(owner_id, value)
.
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<T: ?Sized> QCell<T>
impl<T: ?Sized> QCell<T>
Sourcepub fn ro<'a>(&'a self, owner: &'a QCellOwner) -> &'a T
pub fn ro<'a>(&'a self, owner: &'a QCellOwner) -> &'a T
Convenience method to borrow a cell immutably when the owner
is a QCellOwner
. Equivalent to QCellOwner::ro
. See
QCellOwnerSeq::ro
or QCellOwnerPinned::ro
to borrow
for other owner types.
Sourcepub fn rw<'a>(&'a self, owner: &'a mut QCellOwner) -> &'a mut T
pub fn rw<'a>(&'a self, owner: &'a mut QCellOwner) -> &'a mut T
Convenience method to borrow a cell mutably when the owner is
a QCellOwner
. Equivalent to QCellOwner::rw
. See
QCellOwnerSeq::rw
or QCellOwnerPinned::rw
to borrow
for other owner types.
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 QCell::rw
or QCellOwner::rw
to get
a mutable reference to the contents of the cell.
Safety: This call borrows QCell
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.