Struct lazycell::AtomicLazyCell
source · [−]pub struct AtomicLazyCell<T> { /* private fields */ }
Expand description
A lazily filled and thread-safe Cell
, with frozen contents.
Implementations
sourceimpl<T> AtomicLazyCell<T>
impl<T> AtomicLazyCell<T>
sourcepub fn new() -> AtomicLazyCell<T>
pub fn new() -> AtomicLazyCell<T>
Creates a new, empty, AtomicLazyCell
.
sourcepub fn fill(&self, t: T) -> Result<(), T>
pub fn fill(&self, t: T) -> Result<(), T>
Put a value into this cell.
This function will return Err(value)
if the cell is already full.
sourcepub fn replace(&mut self, value: T) -> Option<T>
pub fn replace(&mut self, value: T) -> Option<T>
Put a value into this cell.
Note that this function is infallible but requires &mut self
. By
requiring &mut self
we’re guaranteed that no active borrows to this
cell can exist so we can always fill in the value. This may not always
be usable, however, as &mut self
may not be possible to borrow.
Return value
This function returns the previous value, if any.
sourcepub fn borrow(&self) -> Option<&T>
pub fn borrow(&self) -> Option<&T>
Borrows the contents of this lazy cell for the duration of the cell itself.
This function will return Some
if the cell has been previously
initialized, and None
if it has not yet been initialized.
sourcepub fn into_inner(self) -> Option<T>
pub fn into_inner(self) -> Option<T>
Consumes this LazyCell
, returning the underlying value.
sourceimpl<T: Copy> AtomicLazyCell<T>
impl<T: Copy> AtomicLazyCell<T>
Trait Implementations
sourceimpl<T: Clone> Clone for AtomicLazyCell<T>
impl<T: Clone> Clone for AtomicLazyCell<T>
sourcefn clone(&self) -> AtomicLazyCell<T>
fn clone(&self) -> AtomicLazyCell<T>
Create a clone of this AtomicLazyCell
If self has not been initialized, returns an uninitialized AtomicLazyCell
otherwise returns an AtomicLazyCell
already initialized with a clone of the
contents of self.
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<T: Debug> Debug for AtomicLazyCell<T>
impl<T: Debug> Debug for AtomicLazyCell<T>
sourceimpl<T> Default for AtomicLazyCell<T>
impl<T> Default for AtomicLazyCell<T>
impl<T: Send> Send for AtomicLazyCell<T>
impl<T: Sync + Send> Sync for AtomicLazyCell<T>
Auto Trait Implementations
impl<T> !RefUnwindSafe for AtomicLazyCell<T>
impl<T> Unpin for AtomicLazyCell<T> where
T: Unpin,
impl<T> UnwindSafe for AtomicLazyCell<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more