LoopCell

Struct LoopCell 

Source
pub struct LoopCell<T>(/* private fields */);
Expand description

Specialized cell for building iterators that handle a value (such as a shared buffer), make it available for processing, modification, etc., and then it needs to be available for the next iteration. Access is performed by LoopCell::access.

Because Cell is not Sync, the LoopCellAccess for LoopCells are not Send. This is particularly important when writing core::future::Futures and asynchronous code, which is often a place where you’d want this (e.g. handling streams of events). In that case, you want LoopSyncCell.

Unlike the internal cell data (which uses an Option), this cell type only implements Default if the type parameter implements Default, and contains the relevant default value.

If you access the LoopCell while something else is holding on to the LoopCell value, then you will not be able to obtain a value. You can also create an empty LoopCell that cannot provide any access

Implementations§

Source§

impl<T> LoopCell<T>

Source

pub const fn new(initial_value: T) -> Self

Create a new LoopCell with the given value

Source

pub fn new_default() -> Self
where T: Default,

Create a new LoopCell using the default value of the type it holds

Source

pub const fn new_empty() -> Self

Create a new, empty LoopCell that can never provide a value.

Source

pub fn access(&self) -> Option<LoopCellAccess<'_, T>>

Attempt to access the loop cell, producing an accessor that will write back any changes to the cell once it is dropped (unless it’s manually disarmed).

Only produces Some if no other accessors are using this LoopCell

Trait Implementations§

Source§

impl<T: Copy + Debug> Debug for LoopCell<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default> Default for LoopCell<T>

Source§

fn default() -> Self

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

impl<T> From<T> for LoopCell<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> !Freeze for LoopCell<T>

§

impl<T> !RefUnwindSafe for LoopCell<T>

§

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

§

impl<T> !Sync for LoopCell<T>

§

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

§

impl<T> UnwindSafe for LoopCell<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<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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.