Skip to main content

Deferrable

Trait Deferrable 

Source
pub trait Deferrable<'a> {
    // Required method
    fn defer<F>(f: F) -> Self
       where F: FnOnce() -> Self + 'a,
             Self: Sized;
}
Expand description

A type class for types that can be constructed lazily.

Required Methods§

Source

fn defer<F>(f: F) -> Self
where F: FnOnce() -> Self + 'a, Self: Sized,

Creates a value from a computation that produces the value.

This function takes a thunk and creates a deferred value that will be computed using the thunk.

§Type Signature

forall self. Deferrable self => (() -> self) -> self

§Type Parameters
  • F: The type of the thunk.
§Parameters
  • f: A thunk that produces the value.
§Returns

The deferred value.

§Examples
use fp_library::{brands::*, functions::*, types::*};

let eval: Thunk<i32> = defer(|| Thunk::new(|| 42));
assert_eq!(eval.evaluate(), 42);

Implementors§

Source§

impl<'a, A> Deferrable<'a> for Lazy<'a, A, RcLazyConfig>
where A: Clone + 'a,

Source§

impl<'a, A, E> Deferrable<'a> for TryLazy<'a, A, E, RcLazyConfig>
where A: Clone + 'a, E: Clone + 'a,

Source§

impl<'a, A, E> Deferrable<'a> for TryThunk<'a, A, E>
where A: 'a, E: 'a,

Source§

impl<'a, A: 'a> Deferrable<'a> for Thunk<'a, A>

Source§

impl<A, E> Deferrable<'static> for TryTrampoline<A, E>
where A: 'static + Send, E: 'static + Send,

Source§

impl<A: 'static + Send> Deferrable<'static> for Trampoline<A>

Source§

impl<A: 'static> Deferrable<'static> for Free<ThunkBrand, A>