pub trait ThunkWrapper {
type Cell<T>;
// Required methods
fn new<T>(value: Option<T>) -> Self::Cell<T>;
fn take<T>(cell: &Self::Cell<T>) -> Option<T>;
}Expand description
Trait for pointers that can wrap a thunk with interior mutability.
This is used by Lazy to store the thunk and clear it after execution.
Required Associated Types§
Required Methods§
Sourcefn new<T>(value: Option<T>) -> Self::Cell<T>
fn new<T>(value: Option<T>) -> Self::Cell<T>
Creates a new cell containing the value.
§Type Signature
forall a. Option a -> Cell a
§Type Parameters
T: The type of the value.
§Parameters
value: The value to wrap.
§Returns
A new cell containing the value.
§Examples
use fp_library::{brands::*, functions::*};
let cell = thunk_wrapper_new::<RcBrand, _>(Some(42));
assert_eq!(thunk_wrapper_take::<RcBrand, _>(&cell), Some(42));Sourcefn take<T>(cell: &Self::Cell<T>) -> Option<T>
fn take<T>(cell: &Self::Cell<T>) -> Option<T>
Takes the value out of the cell.
§Type Signature
forall a. Cell a -> Option a
§Type Parameters
T: The type of the value.
§Parameters
cell: The cell to take the value from.
§Returns
The value if it was present, or None.
§Examples
use fp_library::{brands::*, functions::*};
let cell = thunk_wrapper_new::<RcBrand, _>(Some(42));
assert_eq!(thunk_wrapper_take::<RcBrand, _>(&cell), Some(42));
assert_eq!(thunk_wrapper_take::<RcBrand, _>(&cell), None);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.