pub struct RcLazyConfig;Expand description
Single-threaded memoization using Rc<LazyCell>.
Not thread-safe. Use ArcLazyConfig for multi-threaded contexts.
Trait Implementations§
Source§impl LazyConfig for RcLazyConfig
impl LazyConfig for RcLazyConfig
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 = RcLazyConfig::lazy_new(Box::new(|| 42));
assert_eq!(*RcLazyConfig::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 = RcLazyConfig::try_lazy_new(Box::new(|| Ok::<i32, ()>(42)));
assert_eq!(RcLazyConfig::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 = RcLazyConfig::lazy_new(Box::new(|| 42));
assert_eq!(*RcLazyConfig::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 = RcLazyConfig::try_lazy_new(Box::new(|| Ok::<i32, ()>(42)));
assert_eq!(RcLazyConfig::try_evaluate(&lazy), Ok(&42));Source§type Lazy<'a, A: 'a> = Rc<LazyCell<A, Box<dyn FnOnce() -> A + 'a>>>
type Lazy<'a, A: 'a> = Rc<LazyCell<A, Box<dyn FnOnce() -> A + 'a>>>
The lazy cell type for infallible memoization.
Auto Trait Implementations§
impl Freeze for RcLazyConfig
impl RefUnwindSafe for RcLazyConfig
impl Send for RcLazyConfig
impl Sync for RcLazyConfig
impl Unpin for RcLazyConfig
impl UnwindSafe for RcLazyConfig
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