[−][src]Struct lazycell::LazyCell
A lazily filled Cell
, with mutable contents.
A LazyCell
is completely frozen once filled, unless you have &mut
access to it, in which case LazyCell::borrow_mut
may be used to mutate the
contents.
Methods
impl<T> LazyCell<T>
[src]
pub fn new() -> LazyCell<T>
[src]
Creates a new, empty, LazyCell
.
pub fn fill(&self, value: T) -> Result<(), T>
[src]
Put a value into this cell.
This function will return Err(value)
is the cell is already full.
pub fn replace(&mut self, value: T) -> Option<T>
[src]
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.
pub fn filled(&self) -> bool
[src]
Test whether this cell has been previously filled.
pub fn borrow(&self) -> Option<&T>
[src]
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.
pub fn borrow_mut(&mut self) -> Option<&mut T>
[src]
Borrows the contents of this lazy cell mutably 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.
pub fn borrow_with<F: FnOnce() -> T>(&self, f: F) -> &T
[src]
Borrows the contents of this lazy cell for the duration of the cell itself.
If the cell has not yet been filled, the cell is first filled using the function provided.
Panics
Panics if the cell becomes filled as a side effect of f
.
pub fn borrow_mut_with<F: FnOnce() -> T>(&mut self, f: F) -> &mut T
[src]
Borrows the contents of this LazyCell
mutably for the duration of the
cell itself.
If the cell has not yet been filled, the cell is first filled using the function provided.
Panics
Panics if the cell becomes filled as a side effect of f
.
pub fn try_borrow_with<E, F>(&self, f: F) -> Result<&T, E> where
F: FnOnce() -> Result<T, E>,
[src]
F: FnOnce() -> Result<T, E>,
Same as borrow_with
, but allows the initializing function to fail.
Panics
Panics if the cell becomes filled as a side effect of f
.
pub fn try_borrow_mut_with<E, F>(&mut self, f: F) -> Result<&mut T, E> where
F: FnOnce() -> Result<T, E>,
[src]
F: FnOnce() -> Result<T, E>,
Same as borrow_mut_with
, but allows the initializing function to fail.
Panics
Panics if the cell becomes filled as a side effect of f
.
pub fn into_inner(self) -> Option<T>
[src]
Consumes this LazyCell
, returning the underlying value.
impl<T: Copy> LazyCell<T>
[src]
pub fn get(&self) -> Option<T>
[src]
Returns a copy of the contents of the lazy cell.
This function will return Some
if the cell has been previously initialized,
and None
if it has not yet been initialized.
Trait Implementations
impl<T: Debug> Debug for LazyCell<T>
[src]
impl<T: Clone> Clone for LazyCell<T>
[src]
fn clone(&self) -> LazyCell<T>
[src]
Create a clone of this LazyCell
If self has not been initialized, returns an uninitialized LazyCell
otherwise returns a LazyCell
already initialized with a clone of the
contents of self.
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Default> Default for LazyCell<T>
[src]
Auto Trait Implementations
impl<T> Unpin for LazyCell<T> where
T: Unpin,
T: Unpin,
impl<T> Send for LazyCell<T> where
T: Send,
T: Send,
impl<T> !Sync for LazyCell<T>
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,