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