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§
Source§impl<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>
Sourcepub fn try_into_inner(self) -> Result<U, Option<T>>
pub fn try_into_inner(self) -> Result<U, Option<T>>
Unwrap the contained value, returning Ok(Ok(U))
iff the LazyTransform<T, U>
has been transformed.
§Errors
Iff this instance has neither been transformed yet nor poisoned, Err(Some(T))
is returned.
Iff this instance has been poisoned by error during a call to .get_or_create_or_poison
, Err(None)
is returned.
§Panics
Iff this instance has been poisoned by a panic during transformation.
Source§impl<T, U> LazyTransform<T, U>
impl<T, U> LazyTransform<T, U>
Sourcepub fn get_or_create<F>(&self, f: F) -> &Uwhere
F: FnOnce(T) -> U,
pub fn get_or_create<F>(&self, f: F) -> &Uwhere
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!
§Panics
This method will panic if the instance has been poisoned during a previous transformation attempt.
The method may panic (or deadlock) upon reentrance.
Sourcepub fn try_get_or_create<F, E>(&self, f: F) -> Result<&U, E>
pub fn try_get_or_create<F, E>(&self, f: F) -> Result<&U, E>
Try to get a reference to the transformed value, invoking a fallible 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 successfully invoke its closure, and every call will receive a
reference to the newly transformed value.
The closure can only ever be successfully called once, so think carefully about what transformation you want to apply!
§Errors
Iff f
returns a Result::Err
, this error is returned verbatim.
§Panics
This method will panic if the instance has been poisoned during a previous transformation attempt.
The method may panic (or deadlock) upon reentrance.
Sourcepub fn get_or_create_or_poison<F, E>(&self, f: F) -> Result<&U, Option<E>>
pub fn get_or_create_or_poison<F, E>(&self, f: F) -> Result<&U, Option<E>>
Try to get a reference to the transformed value, invoking a fallible 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!
§Errors
Iff this instance is poisoned, except by panics, Err(None)
is returned.
Iff f
returns a Result::Err
, this error is returned wrapped in Some
.
§Panics
This method will panic if the instance has been poisoned due to a panic during a previous transformation attempt.
The method may panic (or deadlock) upon reentrance.