Struct qcell::QCell

source ·
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>

source

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

source

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>

source

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.

source

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.

source

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.

Trait Implementations§

source§

impl<T: Send + Sync + ?Sized> Sync for QCell<T>

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for QCell<T>

§

impl<T: ?Sized> Send for QCell<T>where T: Send,

§

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

§

impl<T: ?Sized> UnwindSafe for QCell<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, 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.