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);

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Update for AtomicBool

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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>

§

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§