pub struct ArcLazyConfig;Expand description
Thread-safe memoization using Arc<LazyLock>.
Requires A: Send + Sync for the value type.
Trait Implementations§
Source§impl LazyConfig for ArcLazyConfig
impl LazyConfig for ArcLazyConfig
Source§fn lazy_new<'a, A: 'a>(f: Box<Self::Thunk<'a, A>>) -> Self::Lazy<'a, A>
fn lazy_new<'a, A: 'a>(f: Box<Self::Thunk<'a, A>>) -> Self::Lazy<'a, A>
Creates a new lazy cell from an initializer.
§Type Signature
forall self a. self a -> self a
§Type Parameters
'a: The lifetime of the computation.A: The type of the value.
§Parameters
f: The initializer thunk.
§Returns
A new lazy cell.
§Examples
use fp_library::types::*;
let lazy = ArcLazyConfig::lazy_new(Box::new(|| 42));
assert_eq!(*ArcLazyConfig::evaluate(&lazy), 42);Source§fn try_lazy_new<'a, A: 'a, E: 'a>(
f: Box<Self::TryThunk<'a, A, E>>,
) -> Self::TryLazy<'a, A, E>
fn try_lazy_new<'a, A: 'a, E: 'a>( f: Box<Self::TryThunk<'a, A, E>>, ) -> Self::TryLazy<'a, A, E>
Creates a new fallible lazy cell from an initializer.
§Type Signature
forall self a e. self a e -> self a e
§Type Parameters
'a: The lifetime of the computation.A: The type of the value.E: The type of the error.
§Parameters
f: The initializer thunk.
§Returns
A new fallible lazy cell.
§Examples
use fp_library::types::*;
let lazy = ArcLazyConfig::try_lazy_new(Box::new(|| Ok::<i32, ()>(42)));
assert_eq!(ArcLazyConfig::try_evaluate(&lazy), Ok(&42));Source§fn evaluate<'a, 'b, A: 'a>(lazy: &'b Self::Lazy<'a, A>) -> &'b A
fn evaluate<'a, 'b, A: 'a>(lazy: &'b Self::Lazy<'a, A>) -> &'b A
Forces evaluation and returns a reference.
§Type Signature
forall self a. self a -> a
§Type Parameters
'a: The lifetime of the computation.'b: The lifetime of the reference.A: The type of the value.
§Parameters
lazy: The lazy cell to evaluate.
§Returns
A reference to the value.
§Examples
use fp_library::types::*;
let lazy = ArcLazyConfig::lazy_new(Box::new(|| 42));
assert_eq!(*ArcLazyConfig::evaluate(&lazy), 42);Source§fn try_evaluate<'a, 'b, A: 'a, E: 'a>(
lazy: &'b Self::TryLazy<'a, A, E>,
) -> Result<&'b A, &'b E>
fn try_evaluate<'a, 'b, A: 'a, E: 'a>( lazy: &'b Self::TryLazy<'a, A, E>, ) -> Result<&'b A, &'b E>
Forces evaluation and returns a reference to the result.
§Type Signature
forall self a e. self a e -> Result a e
§Type Parameters
'a: The lifetime of the computation.'b: The lifetime of the reference.A: The type of the value.E: The type of the error.
§Parameters
lazy: The fallible lazy cell to evaluate.
§Returns
A result containing a reference to the value or error.
§Examples
use fp_library::types::*;
let lazy = ArcLazyConfig::try_lazy_new(Box::new(|| Ok::<i32, ()>(42)));
assert_eq!(ArcLazyConfig::try_evaluate(&lazy), Ok(&42));Source§type Lazy<'a, A: 'a> = Arc<LazyLock<A, Box<dyn FnOnce() -> A + Send + 'a>>>
type Lazy<'a, A: 'a> = Arc<LazyLock<A, Box<dyn FnOnce() -> A + Send + 'a>>>
The lazy cell type for infallible memoization.
Auto Trait Implementations§
impl Freeze for ArcLazyConfig
impl RefUnwindSafe for ArcLazyConfig
impl Send for ArcLazyConfig
impl Sync for ArcLazyConfig
impl Unpin for ArcLazyConfig
impl UnwindSafe for ArcLazyConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more