Struct lazyonce::LazyOnce [−][src]
pub struct LazyOnce<T> { /* fields omitted */ }
Wrapper type for lazy initialization
Methods
impl<T> LazyOnce<T>
[src]
impl<T> LazyOnce<T>
pub fn new() -> Self
[src]
pub fn new() -> Self
pub fn get(
&self,
f: impl FnOnce() -> T
) -> &T
[src]
pub fn get(
&self,
f: impl FnOnce() -> T
) -> &T
Get cached value, or if no value has been cached yet, compute it using the callback function.
If the callback panics, any use of the cell will panic, too.
pub fn try_get(&self) -> Option<&T>
[src]
pub fn try_get(&self) -> Option<&T>
Get cached value or None
if the cell is still empty
pub fn get_mut(
&mut self,
f: impl FnOnce() -> T
) -> &mut T
[src]
pub fn get_mut(
&mut self,
f: impl FnOnce() -> T
) -> &mut T
Get mutable reference to the cached value, or if no value has been cached yet, compute it using the callback function.
pub fn expect(&self, s: &str) -> &T
[src]
pub fn expect(&self, s: &str) -> &T
Assume the value has already been computed. Crash if the cell is empty.
Panics
If get()
hasn't been called yet.
pub fn into_inner(self) -> Option<T>
[src]
pub fn into_inner(self) -> Option<T>
Return computed value or None
if the cell is empty.
Unlike try_get
this returns an owned value, permanently "unwrapping" the cell.