pub struct SetOnce<T> { /* private fields */ }Expand description
A container that can be populated at most once. Thread safe.
Once the a SetOnce is populated, it remains populated by the same object for the
lifetime Self.
§Invariants
initmay only increase in value.initmay only assume values in the range0..=2.init == 0if and only ifvalueis uninitialized.init == 1if and only if there is exactly one thread with exclusive access toself.value.init == 2if and only ifvalueis initialized and valid for shared access.
§Example
let value = SetOnce::new();
assert_eq!(None, value.as_ref());
let status = value.populate(42u8);
assert_eq!(true, status);
assert_eq!(Some(&42u8), value.as_ref());
assert_eq!(Some(42u8), value.copy());
let status = value.populate(101u8);
assert_eq!(false, status);
assert_eq!(Some(&42u8), value.as_ref());
assert_eq!(Some(42u8), value.copy());Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for SetOnce<T>
impl<T> !RefUnwindSafe for SetOnce<T>
impl<T> Send for SetOnce<T>where
T: Send,
impl<T> !Sync for SetOnce<T>
impl<T> Unpin for SetOnce<T>where
T: Unpin,
impl<T> UnwindSafe for SetOnce<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more
Source§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
Initializes
slot. Read more