Skip to main content

ArcLazyConfig

Struct ArcLazyConfig 

Source
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

Source§

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>

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

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>

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>>>

The lazy cell type for infallible memoization.
Source§

type TryLazy<'a, A: 'a, E: 'a> = Arc<LazyLock<Result<A, E>, Box<dyn FnOnce() -> Result<A, E> + Send + 'a>>>

The lazy cell type for fallible memoization.
Source§

type Thunk<'a, A: 'a> = dyn FnOnce() -> A + Send + 'a

The type of the initializer thunk.
Source§

type TryThunk<'a, A: 'a, E: 'a> = dyn FnOnce() -> Result<A, E> + Send + 'a

The type of the fallible initializer thunk.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.