Update

Trait Update 

Source
pub trait Update {
    type Type;

    // Required method
    fn fetch_update<F>(
        &self,
        fetch_order: Ordering,
        set_order: Ordering,
        f: F,
    ) -> Result<Self::Type, Self::Type>
       where F: FnMut(Self::Type) -> Option<Self::Type>;
}
Expand description

Fetches the value, and applies a function to it that returns an optional new value.

Required Associated Types§

Source

type Type

The underlying type

Required Methods§

Source

fn fetch_update<F>( &self, fetch_order: Ordering, set_order: Ordering, f: F, ) -> Result<Self::Type, Self::Type>
where F: FnMut(Self::Type) -> Option<Self::Type>,

Fetches the value, and applies a function to it that returns an optional new value.

Returns a Result of Ok(previous_value) if the function returned Some(_), else Err(previous_value).

§Examples
use std::sync::atomic::{AtomicU8, Ordering};
use atomic_traits::{Atomic, fetch};

let x = AtomicU8::new(7);
assert_eq!(fetch::Update::fetch_update(&x, Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(7));
assert_eq!(fetch::Update::fetch_update(&x, Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(7));
assert_eq!(fetch::Update::fetch_update(&x, Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(8));
assert_eq!(Atomic::load(&x, Ordering::SeqCst), 9);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Update for AtomicBool

Source§

type Type = bool

Source§

fn fetch_update<F>( &self, fetch_order: Ordering, set_order: Ordering, f: F, ) -> Result<Self::Type, Self::Type>
where F: FnMut(Self::Type) -> Option<Self::Type>,

Source§

impl Update for AtomicI8

Source§

type Type = i8

Source§

fn fetch_update<F>( &self, fetch_order: Ordering, set_order: Ordering, f: F, ) -> Result<Self::Type, Self::Type>
where F: FnMut(Self::Type) -> Option<Self::Type>,

Source§

impl Update for AtomicI16

Source§

type Type = i16

Source§

fn fetch_update<F>( &self, fetch_order: Ordering, set_order: Ordering, f: F, ) -> Result<Self::Type, Self::Type>
where F: FnMut(Self::Type) -> Option<Self::Type>,

Source§

impl Update for AtomicI32

Source§

type Type = i32

Source§

fn fetch_update<F>( &self, fetch_order: Ordering, set_order: Ordering, f: F, ) -> Result<Self::Type, Self::Type>
where F: FnMut(Self::Type) -> Option<Self::Type>,

Source§

impl Update for AtomicI64

Source§

type Type = i64

Source§

fn fetch_update<F>( &self, fetch_order: Ordering, set_order: Ordering, f: F, ) -> Result<Self::Type, Self::Type>
where F: FnMut(Self::Type) -> Option<Self::Type>,

Source§

impl Update for AtomicIsize

Source§

type Type = isize

Source§

fn fetch_update<F>( &self, fetch_order: Ordering, set_order: Ordering, f: F, ) -> Result<Self::Type, Self::Type>
where F: FnMut(Self::Type) -> Option<Self::Type>,

Source§

impl Update for AtomicU8

Source§

type Type = u8

Source§

fn fetch_update<F>( &self, fetch_order: Ordering, set_order: Ordering, f: F, ) -> Result<Self::Type, Self::Type>
where F: FnMut(Self::Type) -> Option<Self::Type>,

Source§

impl Update for AtomicU16

Source§

type Type = u16

Source§

fn fetch_update<F>( &self, fetch_order: Ordering, set_order: Ordering, f: F, ) -> Result<Self::Type, Self::Type>
where F: FnMut(Self::Type) -> Option<Self::Type>,

Source§

impl Update for AtomicU32

Source§

type Type = u32

Source§

fn fetch_update<F>( &self, fetch_order: Ordering, set_order: Ordering, f: F, ) -> Result<Self::Type, Self::Type>
where F: FnMut(Self::Type) -> Option<Self::Type>,

Source§

impl Update for AtomicU64

Source§

type Type = u64

Source§

fn fetch_update<F>( &self, fetch_order: Ordering, set_order: Ordering, f: F, ) -> Result<Self::Type, Self::Type>
where F: FnMut(Self::Type) -> Option<Self::Type>,

Source§

impl Update for AtomicUsize

Source§

type Type = usize

Source§

fn fetch_update<F>( &self, fetch_order: Ordering, set_order: Ordering, f: F, ) -> Result<Self::Type, Self::Type>
where F: FnMut(Self::Type) -> Option<Self::Type>,

Source§

impl<T> Update for AtomicPtr<T>

Source§

type Type = *mut T

Source§

fn fetch_update<F>( &self, fetch_order: Ordering, set_order: Ordering, f: F, ) -> Result<Self::Type, Self::Type>
where F: FnMut(Self::Type) -> Option<Self::Type>,

Implementors§