Skip to main content

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".

Implementations on Foreign Types§

Source§

impl Update for Atomic<bool>

Source§

type Type = bool

Source§

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

Source§

impl Update for Atomic<i8>

Source§

type Type = i8

Source§

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

Source§

impl Update for Atomic<i16>

Source§

type Type = i16

Source§

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

Source§

impl Update for Atomic<i32>

Source§

type Type = i32

Source§

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

Source§

impl Update for Atomic<i64>

Source§

type Type = i64

Source§

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

Source§

impl Update for Atomic<isize>

Source§

type Type = isize

Source§

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

Source§

impl Update for Atomic<u8>

Source§

type Type = u8

Source§

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

Source§

impl Update for Atomic<u16>

Source§

type Type = u16

Source§

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

Source§

impl Update for Atomic<u32>

Source§

type Type = u32

Source§

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

Source§

impl Update for Atomic<u64>

Source§

type Type = u64

Source§

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

Source§

impl Update for Atomic<usize>

Source§

type Type = usize

Source§

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

Source§

impl<T> Update for Atomic<*mut T>

Source§

type Type = *mut T

Source§

fn fetch_update<F>( &self, fetch_order: Ordering, set_order: Ordering, f: F, ) -> Result<<Atomic<*mut T> as Update>::Type, <Atomic<*mut T> as Update>::Type>
where F: FnMut(<Atomic<*mut T> as Update>::Type) -> Option<<Atomic<*mut T> as Update>::Type>,

Implementors§

Source§

impl<T> Update for AtomicNumber<T>
where T: PrimitiveAtomicNumber + FromPrimitive,

Source§

type Type = T