pub struct AtomOption<T: Send + Sync + 'static> { /* private fields */ }Expand description
Like Atom<T> but allows a null/empty state.
This is useful for values that may not be present initially or can be removed at runtime.
§Examples
use kovan::AtomOption;
let opt: AtomOption<String> = AtomOption::none();
assert!(opt.load().is_none());
opt.store_some(String::from("hello"));
assert_eq!(&*opt.load().unwrap(), "hello");
let taken = opt.take();
assert_eq!(taken.unwrap(), "hello");
assert!(opt.load().is_none());Implementations§
Source§impl<T: Send + Sync + 'static> AtomOption<T>
impl<T: Send + Sync + 'static> AtomOption<T>
Sourcepub fn load(&self) -> Option<AtomGuard<'_, T>>
pub fn load(&self) -> Option<AtomGuard<'_, T>>
Loads the current value, if present.
Returns None if the atom is empty, or Some(guard) where
the guard dereferences to &T.
Sourcepub fn store_some(&self, val: T)
pub fn store_some(&self, val: T)
Stores a value, retiring any previous value.
Sourcepub fn store_none(&self)
pub fn store_none(&self)
Clears the atom, retiring any current value.
Trait Implementations§
impl<T: Send + Sync + 'static> Send for AtomOption<T>
impl<T: Send + Sync + 'static> Sync for AtomOption<T>
Auto Trait Implementations§
impl<T> !Freeze for AtomOption<T>
impl<T> RefUnwindSafe for AtomOption<T>where
T: RefUnwindSafe,
impl<T> Unpin for AtomOption<T>
impl<T> UnwindSafe for AtomOption<T>where
T: RefUnwindSafe,
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