pub struct LazyArc<T> { /* private fields */ }
Expand description
A thread-safe reference-counting pointer, akin to
Arc<T>
, but with lazy initialization
Implementations§
source§impl<T> LazyArc<T>
impl<T> LazyArc<T>
sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Create a new LazyArc<T>
that is initially empty. It’s “inner” value
will be initialized on first access!
sourcepub fn from_value(value: T) -> Self
pub fn from_value(value: T) -> Self
Create a new LazyArc<T>
that is already initialized to value
.
sourcepub fn from_pointer(pointer: Arc<T>) -> Self
pub fn from_pointer(pointer: Arc<T>) -> Self
Create a new LazyArc<T>
that is already initialized to the given
Arc<T>
pointer.
sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Returns true
, if and only if th “inner” value is initialized.
sourcepub fn or_init_with<F>(&self, init_fn: F) -> Arc<T>where
F: FnOnce() -> T,
pub fn or_init_with<F>(&self, init_fn: F) -> Arc<T>where
F: FnOnce() -> T,
Returns a pointer to the existing “inner” value, or initializes the value right now.
If and only if the “inner” value is not initialized yet, the
function init_fn()
is called to create the value. The “inner” value
is then set to the return value of init_fn()
and a new Arc<T>
pointer to the “inner” value is returned.
sourcepub fn or_try_init_with<E, F>(&self, init_fn: F) -> Result<Arc<T>, E>where
F: FnOnce() -> Result<T, E>,
pub fn or_try_init_with<E, F>(&self, init_fn: F) -> Result<Arc<T>, E>where
F: FnOnce() -> Result<T, E>,
Returns a pointer to the existing “inner” value, or tries to initializes the value right now.
If and only if the “inner” value is not initialized yet, the
function init_fn()
is called to create the value. In case that
init_fn()
returns an error, that error is passed through and the
“inner” value remains in the uninitialized state for now. If the
“inner” value already existed or if it was created successfully just
now, a new Arc<T>
pointer to the “inner” value is returned.
sourcepub fn map<U, F>(&self, map_fn: F) -> Option<U>where
F: FnOnce(&Arc<T>) -> U,
pub fn map<U, F>(&self, map_fn: F) -> Option<U>where
F: FnOnce(&Arc<T>) -> U,
Applies function map_fn()
to the “inner”, if already initialized.
If and only if the “inner” value already is initialize, the function
map_fn()
is called with a reference to the “inner” value and its
return value is passed through. Otherwise the function map_fn()
is
not called and None
is returned.
sourcepub fn value(&self) -> Option<Arc<T>>
pub fn value(&self) -> Option<Arc<T>>
Returns a pointer to the “inner” value, if already initialized.
If and only if the “inner” value already is initialized, the function
returns a new Arc<T>
pointer to the “inner” value. Otherwise, if the
“inner” value is not initialized yet, the value remains in the
uninitialized state and the function returns None
.
sourcepub fn take(&mut self) -> Option<Arc<T>>
pub fn take(&mut self) -> Option<Arc<T>>
Takes the “inner” value out of this LazyRc<T>
instance, if already
initialized.
If and only if the “inner” value already is initialized, the function
returns the Arc<T>
pointer to the current “inner” value and resets
this LazyArc<T>
instance’ “inner” value to the uninitialized state.
Otherwise, the function simply returns None
.
Trait Implementations§
source§impl<T> Clone for LazyArc<T>
impl<T> Clone for LazyArc<T>
source§fn clone(&self) -> LazyArc<T>
fn clone(&self) -> LazyArc<T>
Creates a clone of this LazyArc<T>
instance.
If the “inner” value of this instance is already initialized, the clone will be pointing to the same “inner” value, i.e. the “inner” value is not cloned. Otherwise, the clone will initially be empty; it can be initialized independently from this instance.
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more