Skip to main content

AtomOption

Struct AtomOption 

Source
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>

Source

pub fn none() -> Self

Creates an empty AtomOption.

Source

pub fn some(val: T) -> Self

Creates an AtomOption containing val.

Source

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.

Source

pub fn is_none(&self) -> bool

Returns true if the atom is empty.

Source

pub fn is_some(&self) -> bool

Returns true if the atom contains a value.

Source

pub fn store_some(&self, val: T)

Stores a value, retiring any previous value.

Source

pub fn store_none(&self)

Clears the atom, retiring any current value.

Source

pub fn take(&self) -> Option<T>

Takes the value out, leaving the atom empty.

Returns Some(val) if there was a value, None otherwise.

Trait Implementations§

Source§

impl<T: Send + Sync + 'static + Debug> Debug for AtomOption<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Send + Sync + 'static> Default for AtomOption<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Send + Sync + 'static> Drop for AtomOption<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Send + Sync + 'static> Send for AtomOption<T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.