pub struct OnceCellBrand;Expand description
Brand for OnceCell.
Trait Implementations§
Source§impl Clone for OnceCellBrand
impl Clone for OnceCellBrand
Source§fn clone(&self) -> OnceCellBrand
fn clone(&self) -> OnceCellBrand
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OnceCellBrand
impl Debug for OnceCellBrand
Source§impl Default for OnceCellBrand
impl Default for OnceCellBrand
Source§fn default() -> OnceCellBrand
fn default() -> OnceCellBrand
Source§impl Hash for OnceCellBrand
impl Hash for OnceCellBrand
Source§impl Kind_ad6c20556a82a1f0 for OnceCellBrand
Generated implementation of Kind_ad6c20556a82a1f0 for OnceCellBrand.
impl Kind_ad6c20556a82a1f0 for OnceCellBrand
Generated implementation of Kind_ad6c20556a82a1f0 for OnceCellBrand.
Source§impl Once for OnceCellBrand
impl Once for OnceCellBrand
Source§fn new<A>() -> <Self as Once>::Of<A>
fn new<A>() -> <Self as Once>::Of<A>
Creates a new, uninitialized Once container.
This method creates a new instance of the OnceCell that is initially empty.
§Type Signature
forall a. Once OnceCell => () -> OnceCell a
§Type Parameters
A: The type of the value to be stored in the container.
§Returns
A new, empty OnceCell.
§Examples
use fp_library::functions::*;
use fp_library::brands::OnceCellBrand;
let cell = once_new::<OnceCellBrand, i32>();
assert_eq!(once_get::<OnceCellBrand, _>(&cell), None);Source§fn get<A>(a: &<Self as Once>::Of<A>) -> Option<&A>
fn get<A>(a: &<Self as Once>::Of<A>) -> Option<&A>
Gets a reference to the value if it has been initialized.
This method returns a reference to the value stored in the OnceCell if it has been initialized, otherwise it returns None.
§Type Signature
forall a. Once OnceCell => OnceCell a -> Option a
§Type Parameters
A: The type of the value stored in the container.
§Parameters
a: TheOnceCell.
§Returns
A reference to the value, or None if uninitialized.
§Examples
use fp_library::functions::*;
use fp_library::brands::OnceCellBrand;
let cell = once_new::<OnceCellBrand, i32>();
assert_eq!(once_get::<OnceCellBrand, _>(&cell), None);
once_set::<OnceCellBrand, _>(&cell, 42).unwrap();
assert_eq!(once_get::<OnceCellBrand, _>(&cell), Some(&42));Source§fn get_mut<A>(a: &mut <Self as Once>::Of<A>) -> Option<&mut A>
fn get_mut<A>(a: &mut <Self as Once>::Of<A>) -> Option<&mut A>
Gets a mutable reference to the value if it has been initialized.
This method returns a mutable reference to the value stored in the OnceCell if it has been initialized, otherwise it returns None.
§Type Signature
forall a. Once OnceCell => OnceCell a -> Option a
§Type Parameters
A: The type of the value stored in the container.
§Parameters
a: TheOnceCell.
§Returns
A mutable reference to the value, or None if uninitialized.
§Examples
use fp_library::functions::*;
use fp_library::brands::OnceCellBrand;
let mut cell = once_new::<OnceCellBrand, i32>();
once_set::<OnceCellBrand, _>(&cell, 42).unwrap();
if let Some(val) = once_get_mut::<OnceCellBrand, _>(&mut cell) {
*val += 1;
}
assert_eq!(once_get_mut::<OnceCellBrand, _>(&mut cell), Some(&mut 43));Source§fn set<A>(a: &<Self as Once>::Of<A>, value: A) -> Result<(), A>
fn set<A>(a: &<Self as Once>::Of<A>, value: A) -> Result<(), A>
Sets the value of the container.
This method attempts to set the value of the OnceCell. If the OnceCell is already initialized, it returns the value in the Err variant.
§Type Signature
forall a. Once OnceCell => (OnceCell a, a) -> Result<(), a>
§Type Parameters
A: The type of the value to set.
§Parameters
a: TheOnceCell.value: The value to set.
§Returns
Ok(()) on success, or Err(value) if already initialized.
§Examples
use fp_library::functions::*;
use fp_library::brands::OnceCellBrand;
let cell = once_new::<OnceCellBrand, i32>();
assert!(once_set::<OnceCellBrand, _>(&cell, 42).is_ok());
assert!(once_set::<OnceCellBrand, _>(&cell, 10).is_err());Source§fn get_or_init<A, B: FnOnce() -> A>(a: &<Self as Once>::Of<A>, f: B) -> &A
fn get_or_init<A, B: FnOnce() -> A>(a: &<Self as Once>::Of<A>, f: B) -> &A
Gets the value, initializing it with the closure f if it is not already initialized.
This method returns a reference to the value stored in the OnceCell. If the OnceCell is not initialized, it initializes it using the provided closure f and then returns a reference to the value.
§Type Signature
forall a. Once OnceCell => (OnceCell a, () -> a) -> a
§Type Parameters
A: The type of the value stored in the container.B: The type of the initialization function.
§Parameters
a: TheOnceCell.f: The initialization function.
§Returns
A reference to the value.
§Examples
use fp_library::functions::*;
use fp_library::brands::OnceCellBrand;
let cell = once_new::<OnceCellBrand, i32>();
assert_eq!(*once_get_or_init::<OnceCellBrand, _, _>(&cell, || 42), 42);
assert_eq!(*once_get_or_init::<OnceCellBrand, _, _>(&cell, || 10), 42);Source§fn into_inner<A>(a: <Self as Once>::Of<A>) -> Option<A>
fn into_inner<A>(a: <Self as Once>::Of<A>) -> Option<A>
Consumes the container and returns the value if it has been initialized.
This method consumes the OnceCell and returns the value stored in it if it has been initialized, otherwise it returns None.
§Type Signature
forall a. Once OnceCell => OnceCell a -> Option a
§Type Parameters
A: The type of the value stored in the container.
§Parameters
a: TheOnceCell.
§Returns
The value, or None if uninitialized.
§Examples
use fp_library::functions::*;
use fp_library::brands::OnceCellBrand;
let cell = once_new::<OnceCellBrand, i32>();
once_set::<OnceCellBrand, _>(&cell, 42).unwrap();
assert_eq!(once_into_inner::<OnceCellBrand, _>(cell), Some(42));Source§fn take<A>(a: &mut <Self as Once>::Of<A>) -> Option<A>
fn take<A>(a: &mut <Self as Once>::Of<A>) -> Option<A>
Takes the value out of the container, leaving it uninitialized.
This method takes the value out of the OnceCell, leaving the OnceCell in an uninitialized state. It returns the value if it was initialized, otherwise it returns None.
§Type Signature
forall a. Once OnceCell => OnceCell a -> Option a
§Type Parameters
A: The type of the value stored in the container.
§Parameters
a: TheOnceCell.
§Returns
The value, or None if uninitialized.
§Examples
use fp_library::functions::*;
use fp_library::brands::OnceCellBrand;
let mut cell = once_new::<OnceCellBrand, i32>();
once_set::<OnceCellBrand, _>(&cell, 42).unwrap();
assert_eq!(once_take::<OnceCellBrand, _>(&mut cell), Some(42));
assert_eq!(once_take::<OnceCellBrand, _>(&mut cell), None);type Of<A> = <OnceCellBrand as Kind_ad6c20556a82a1f0>::Of<A>
Source§impl Ord for OnceCellBrand
impl Ord for OnceCellBrand
Source§fn cmp(&self, other: &OnceCellBrand) -> Ordering
fn cmp(&self, other: &OnceCellBrand) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for OnceCellBrand
impl PartialEq for OnceCellBrand
Source§impl PartialOrd for OnceCellBrand
impl PartialOrd for OnceCellBrand
impl Copy for OnceCellBrand
impl Eq for OnceCellBrand
impl StructuralPartialEq for OnceCellBrand
Auto Trait Implementations§
impl Freeze for OnceCellBrand
impl RefUnwindSafe for OnceCellBrand
impl Send for OnceCellBrand
impl Sync for OnceCellBrand
impl Unpin for OnceCellBrand
impl UnwindSafe for OnceCellBrand
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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