pub trait Sub {
type Type;
// Required method
fn fetch_sub(&self, val: Self::Type, order: Ordering) -> Self::Type;
}Expand description
Subtracts from the current value, returning the previous value.
Required Associated Types§
Required Methods§
Sourcefn fetch_sub(&self, val: Self::Type, order: Ordering) -> Self::Type
fn fetch_sub(&self, val: Self::Type, order: Ordering) -> Self::Type
Subtracts from the current value, returning the previous value.
This operation wraps around on overflow.
§Examples
use std::sync::atomic::{AtomicU8, Ordering};
use atomic_traits::{Atomic, fetch};
let foo = AtomicU8::new(20);
assert_eq!(fetch::Sub::fetch_sub(&foo, 10, Ordering::SeqCst), 20);
assert_eq!(Atomic::load(&foo, Ordering::SeqCst), 10);