Struct AsyncAtomic

Source
pub struct AsyncAtomic<T: Atom> { /* private fields */ }
Expand description

Atomic value that also contains Waker to notify subscriber asynchronously.

There is only a single waker, so there should be only single subscription at a time. Otherwise older subscriptions will not receive updates anymore.

Implementations§

Source§

impl<T: Atom> AsyncAtomic<T>

Source

pub fn new(value: T) -> Self

Source

pub const fn from_impl(repr: <T::Repr as PrimitiveAtom>::Impl) -> Self

Source

pub fn load(&self) -> T

Source

pub fn store(&self, val: T)

Source

pub fn swap(&self, val: T) -> T

Source

pub fn compare_exchange(&self, current: T, new: T) -> Result<T, T>

Source

pub fn fetch_update<F: FnMut(T) -> Option<T>>(&self, f: F) -> Result<T, T>

Source§

impl<T: AtomLogic> AsyncAtomic<T>

Source

pub fn fetch_and(&self, val: T) -> T

Source

pub fn fetch_or(&self, val: T) -> T

Source

pub fn fetch_xor(&self, val: T) -> T

Source§

impl<T: AtomInteger> AsyncAtomic<T>

Source

pub fn fetch_add(&self, val: T) -> T

Source

pub fn fetch_sub(&self, val: T) -> T

Source

pub fn fetch_max(&self, val: T) -> T

Source

pub fn fetch_min(&self, val: T) -> T

Trait Implementations§

Source§

impl<T: Atom> AsRef<AsyncAtomic<T>> for AsyncAtomic<T>

Source§

fn as_ref(&self) -> &AsyncAtomic<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Atom> AsyncAtomicRef for AsyncAtomic<T>

Source§

type Item = T

Type stored in atomic.
Source§

fn as_atomic(&self) -> &AsyncAtomic<Self::Item>

Get reference to original atomic structure.
Source§

fn wait<F: FnMut(Self::Item) -> bool>(&self, pred: F) -> Wait<&Self, F>

Asynchronously wait for predicate to be true.
Source§

fn wait_and_update<F: FnMut(Self::Item) -> Option<Self::Item>>( &self, map: F, ) -> WaitAndUpdate<&Self, F>

Asynchronously wait until map returned Some(x) and then store x in atomic. Read more
Source§

fn changed(self) -> Changed<Self>
where Self: Sized, Self::Item: PartialEq + Clone,

Convert subscriber into stream that yields when value is changed.
Source§

impl<T: Debug + Atom> Debug for AsyncAtomic<T>

Source§

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

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

impl<T: Default + Atom> Default for AsyncAtomic<T>

Source§

fn default() -> AsyncAtomic<T>

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

Auto Trait Implementations§

§

impl<T> !Freeze for AsyncAtomic<T>

§

impl<T> !RefUnwindSafe for AsyncAtomic<T>

§

impl<T> Send for AsyncAtomic<T>

§

impl<T> Sync for AsyncAtomic<T>

§

impl<T> Unpin for AsyncAtomic<T>

§

impl<T> UnwindSafe for AsyncAtomic<T>
where <<T as Atom>::Repr as PrimitiveAtom>::Impl: UnwindSafe,

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.