OfferCell

Struct OfferCell 

Source
pub struct OfferCell<T> { /* private fields */ }
Expand description

A data container that can offer optional ownership of its stored information

Implementations§

Source§

impl<T> OfferCell<T>

Source

pub fn empty() -> Self

Returns an empty cell

Source

pub fn new(item: T) -> Self

Returns a new cell that stores item

Source

pub fn is_empty(&self) -> bool

Returns true if the cell is empty

Source

pub fn item(&self) -> Option<&T>

Returns a reference to the stored item

Source

pub fn item_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to the stored item

Source

pub fn take(&mut self) -> Option<T>

Returns the stored data leaving nothing in its place

Source

pub fn offer(&mut self) -> Option<Offering<'_, T>>

Offers optional ownership of the stored data as a Offering item

Source

pub fn insert_offer(&mut self, item: T) -> Offering<'_, T>

Inserts item into the cell and returns the item as an offering

Source

pub fn offer_or_insert(&mut self, insert: impl FnMut() -> T) -> Offering<'_, T>

Inserts data if there is none currently, then returns the stored data

Source

pub fn entry(&mut self) -> OfferEntry<'_, T>

Returns an Offering if there is one. Otherwise returns an EmptyOffering.

Trait Implementations§

Source§

impl<T> Default for OfferCell<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for OfferCell<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for OfferCell<T>
where T: RefUnwindSafe,

§

impl<T> Send for OfferCell<T>
where T: Send,

§

impl<T> Sync for OfferCell<T>
where T: Sync,

§

impl<T> Unpin for OfferCell<T>
where T: Unpin,

§

impl<T> UnwindSafe for OfferCell<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.