pub fn set<Brand, A>(a: &<Brand as Once>::Of<A>, value: A) -> Result<(), A>where
Brand: Once,Expand description
Sets the value of the container.
This function attempts to set the value of the container. If the container is already initialized, it returns the value in the Err variant.
Free function version that dispatches to the type class’ associated function.
§Type Signature
forall a. Once f => (f a, a) -> Result<(), a>
§Type Parameters
Brand: The brand of the container.A: The type of the value to set.
§Parameters
a: The container.value: The value to set.
§Returns
Ok(()) on success, or Err(value) if already initialized.
§Examples
use fp_library::classes::once::{new, set};
use fp_library::brands::OnceCellBrand;
let cell = new::<OnceCellBrand, i32>();
assert!(set::<OnceCellBrand, _>(&cell, 42).is_ok());
assert!(set::<OnceCellBrand, _>(&cell, 10).is_err());