Struct lazy_init::LazyTransform
source · [−]pub struct LazyTransform<T, U> { /* private fields */ }
Expand description
LazyTransform<T, U>
is a synchronized holder type, that holds a value of
type T until it is lazily converted into a value of type U.
Implementations
sourceimpl<T, U> LazyTransform<T, U>
impl<T, U> LazyTransform<T, U>
sourcepub fn new(t: T) -> LazyTransform<T, U>
pub fn new(t: T) -> LazyTransform<T, U>
Construct a new, untransformed LazyTransform<T, U>
with an argument of
type T.
sourcepub fn into_inner(self) -> Result<U, T>
pub fn into_inner(self) -> Result<U, T>
Unwrap the contained value, returning Ok(U)
if the LazyTransform<T, U>
has been
transformed or Err(T)
if it has not.
sourceimpl<T, U> LazyTransform<T, U>
impl<T, U> LazyTransform<T, U>
sourcepub fn get_or_create<F>(&self, f: F) -> &U where
F: FnOnce(T) -> U,
pub fn get_or_create<F>(&self, f: F) -> &U where
F: FnOnce(T) -> U,
Get a reference to the transformed value, invoking f
to transform it
if the LazyTransform<T, U>
has yet to be transformed. It is
guaranteed that if multiple calls to get_or_create
race, only one
will invoke its closure, and every call will receive a reference to the
newly transformed value.
The closure can only ever be called once, so think carefully about what transformation you want to apply!
Trait Implementations
sourceimpl<T, U> Clone for LazyTransform<T, U> where
T: Clone,
U: Clone,
impl<T, U> Clone for LazyTransform<T, U> where
T: Clone,
U: Clone,
sourceimpl<T, U> Default for LazyTransform<T, U> where
T: Default,
impl<T, U> Default for LazyTransform<T, U> where
T: Default,
impl<T, U> Sync for LazyTransform<T, U> where
T: Send,
U: Send + Sync,
Auto Trait Implementations
impl<T, U> !RefUnwindSafe for LazyTransform<T, U>
impl<T, U> Send for LazyTransform<T, U> where
T: Send,
U: Send,
impl<T, U> Unpin for LazyTransform<T, U> where
T: Unpin,
U: Unpin,
impl<T, U> UnwindSafe for LazyTransform<T, U> where
T: UnwindSafe,
U: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more