Skip to main content

PrimitiveAtomic

Trait PrimitiveAtomic 

Source
pub trait PrimitiveAtomic:
    Sealed
    + Sized
    + Send
    + Sync {
    type Value: Copy + Send + Sync + AtomicPrimitive<Atomic = Self>;

Show 14 methods // Required methods fn new(value: Self::Value) -> Self; fn get_mut(&mut self) -> &mut Self::Value; fn into_inner(self) -> Self::Value; fn load(&self, order: Ordering) -> Self::Value; fn store(&self, value: Self::Value, order: Ordering); fn swap(&self, value: Self::Value, order: Ordering) -> Self::Value; fn compare_exchange( &self, current: Self::Value, new: Self::Value, success: Ordering, failure: Ordering, ) -> Result<Self::Value, Self::Value>; fn compare_exchange_weak( &self, current: Self::Value, new: Self::Value, success: Ordering, failure: Ordering, ) -> Result<Self::Value, Self::Value>; fn fetch_update<F>( &self, set_order: Ordering, fetch_order: Ordering, f: F, ) -> Result<Self::Value, Self::Value> where F: FnMut(Self::Value) -> Option<Self::Value>; fn fetch_and(&self, val: Self::Value, order: Ordering) -> Self::Value; fn fetch_nand(&self, val: Self::Value, order: Ordering) -> Self::Value; fn fetch_or(&self, val: Self::Value, order: Ordering) -> Self::Value; fn fetch_xor(&self, val: Self::Value, order: Ordering) -> Self::Value; fn as_ptr(&self) -> *mut Self::Value;
}
Expand description

Trait for all primitive atomic types, including AtomicBool and all atomic integer types.

This encapsulates trait implementations and inherent methods that are common among all of the primitive atomic types: AtomicBool, AtomicU8, AtomicU16, AtomicU32, AtomicU64, AtomicUsize, AtomicI8, AtomicI16, AtomicI32, AtomicI64, and AtomicIsize.

See the corresponding items on the individual types for more documentation and examples.

This trait is sealed to prevent downstream implementations.

Required Associated Types§

Source

type Value: Copy + Send + Sync + AtomicPrimitive<Atomic = Self>

The non-atomic type corresponding to this atomic type.

The AtomicPrimitive bound is the only addition beyond standard library functionality, enabling bidirectional navigation between atomic and non-atomic types.

Required Methods§

Source

fn new(value: Self::Value) -> Self

Creates a new atomic value.

Source

fn get_mut(&mut self) -> &mut Self::Value

Returns a mutable reference to the underlying value.

Source

fn into_inner(self) -> Self::Value

Consumes the atomic and returns the contained value.

Source

fn load(&self, order: Ordering) -> Self::Value

Loads a value from the atomic.

Source

fn store(&self, value: Self::Value, order: Ordering)

Stores a value into the atomic.

Source

fn swap(&self, value: Self::Value, order: Ordering) -> Self::Value

Stores a value into the atomic, returning the previous value.

Source

fn compare_exchange( &self, current: Self::Value, new: Self::Value, success: Ordering, failure: Ordering, ) -> Result<Self::Value, Self::Value>

Stores a value into the atomic if the current value is the same as current.

Source

fn compare_exchange_weak( &self, current: Self::Value, new: Self::Value, success: Ordering, failure: Ordering, ) -> Result<Self::Value, Self::Value>

Stores a value into the atomic if the current value is the same as current. Unlike compare_exchange, this function is allowed to spuriously fail.

Source

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

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

Source

fn fetch_and(&self, val: Self::Value, order: Ordering) -> Self::Value

Bitwise “and” with the current value. Returns the previous value.

Source

fn fetch_nand(&self, val: Self::Value, order: Ordering) -> Self::Value

Bitwise “nand” with the current value. Returns the previous value.

Source

fn fetch_or(&self, val: Self::Value, order: Ordering) -> Self::Value

Bitwise “or” with the current value. Returns the previous value.

Source

fn fetch_xor(&self, val: Self::Value, order: Ordering) -> Self::Value

Bitwise “xor” with the current value. Returns the previous value.

Source

fn as_ptr(&self) -> *mut Self::Value

Returns a raw pointer to the underlying value.

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 PrimitiveAtomic for AtomicBool

Source§

fn new(value: bool) -> Self

See the inherent new method.

Source§

fn get_mut(&mut self) -> &mut bool

See the inherent get_mut method.

Source§

fn into_inner(self) -> bool

See the inherent into_inner method.

Source§

fn load(&self, order: Ordering) -> bool

See the inherent load method.

Source§

fn swap(&self, value: bool, order: Ordering) -> bool

See the inherent swap method.

Source§

fn compare_exchange( &self, current: bool, new: bool, success: Ordering, failure: Ordering, ) -> Result<bool, bool>

See the inherent compare_exchange method.

Source§

fn compare_exchange_weak( &self, current: bool, new: bool, success: Ordering, failure: Ordering, ) -> Result<bool, bool>

See the inherent compare_exchange_weak method.

Source§

fn fetch_and(&self, val: bool, order: Ordering) -> bool

See the inherent fetch_and method.

Source§

fn fetch_nand(&self, val: bool, order: Ordering) -> bool

See the inherent fetch_nand method.

Source§

fn fetch_or(&self, val: bool, order: Ordering) -> bool

See the inherent fetch_or method.

Source§

fn fetch_xor(&self, val: bool, order: Ordering) -> bool

See the inherent fetch_xor method.

Source§

fn as_ptr(&self) -> *mut bool

See the inherent as_ptr method.

Source§

type Value = bool

Source§

fn store(&self, value: bool, order: Ordering)

Source§

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

Source§

impl PrimitiveAtomic for AtomicI8

Source§

fn new(value: i8) -> Self

See the inherent new method.

Source§

fn get_mut(&mut self) -> &mut i8

See the inherent get_mut method.

Source§

fn into_inner(self) -> i8

See the inherent into_inner method.

Source§

fn load(&self, order: Ordering) -> i8

See the inherent load method.

Source§

fn swap(&self, value: i8, order: Ordering) -> i8

See the inherent swap method.

Source§

fn compare_exchange( &self, current: i8, new: i8, success: Ordering, failure: Ordering, ) -> Result<i8, i8>

See the inherent compare_exchange method.

Source§

fn compare_exchange_weak( &self, current: i8, new: i8, success: Ordering, failure: Ordering, ) -> Result<i8, i8>

See the inherent compare_exchange_weak method.

Source§

fn fetch_and(&self, val: i8, order: Ordering) -> i8

See the inherent fetch_and method.

Source§

fn fetch_nand(&self, val: i8, order: Ordering) -> i8

See the inherent fetch_nand method.

Source§

fn fetch_or(&self, val: i8, order: Ordering) -> i8

See the inherent fetch_or method.

Source§

fn fetch_xor(&self, val: i8, order: Ordering) -> i8

See the inherent fetch_xor method.

Source§

fn as_ptr(&self) -> *mut i8

See the inherent as_ptr method.

Source§

type Value = i8

Source§

fn store(&self, value: i8, order: Ordering)

Source§

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

Source§

impl PrimitiveAtomic for AtomicI16

Source§

fn new(value: i16) -> Self

See the inherent new method.

Source§

fn get_mut(&mut self) -> &mut i16

See the inherent get_mut method.

Source§

fn into_inner(self) -> i16

See the inherent into_inner method.

Source§

fn load(&self, order: Ordering) -> i16

See the inherent load method.

Source§

fn swap(&self, value: i16, order: Ordering) -> i16

See the inherent swap method.

Source§

fn compare_exchange( &self, current: i16, new: i16, success: Ordering, failure: Ordering, ) -> Result<i16, i16>

See the inherent compare_exchange method.

Source§

fn compare_exchange_weak( &self, current: i16, new: i16, success: Ordering, failure: Ordering, ) -> Result<i16, i16>

See the inherent compare_exchange_weak method.

Source§

fn fetch_and(&self, val: i16, order: Ordering) -> i16

See the inherent fetch_and method.

Source§

fn fetch_nand(&self, val: i16, order: Ordering) -> i16

See the inherent fetch_nand method.

Source§

fn fetch_or(&self, val: i16, order: Ordering) -> i16

See the inherent fetch_or method.

Source§

fn fetch_xor(&self, val: i16, order: Ordering) -> i16

See the inherent fetch_xor method.

Source§

fn as_ptr(&self) -> *mut i16

See the inherent as_ptr method.

Source§

type Value = i16

Source§

fn store(&self, value: i16, order: Ordering)

Source§

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

Source§

impl PrimitiveAtomic for AtomicI32

Source§

fn new(value: i32) -> Self

See the inherent new method.

Source§

fn get_mut(&mut self) -> &mut i32

See the inherent get_mut method.

Source§

fn into_inner(self) -> i32

See the inherent into_inner method.

Source§

fn load(&self, order: Ordering) -> i32

See the inherent load method.

Source§

fn swap(&self, value: i32, order: Ordering) -> i32

See the inherent swap method.

Source§

fn compare_exchange( &self, current: i32, new: i32, success: Ordering, failure: Ordering, ) -> Result<i32, i32>

See the inherent compare_exchange method.

Source§

fn compare_exchange_weak( &self, current: i32, new: i32, success: Ordering, failure: Ordering, ) -> Result<i32, i32>

See the inherent compare_exchange_weak method.

Source§

fn fetch_and(&self, val: i32, order: Ordering) -> i32

See the inherent fetch_and method.

Source§

fn fetch_nand(&self, val: i32, order: Ordering) -> i32

See the inherent fetch_nand method.

Source§

fn fetch_or(&self, val: i32, order: Ordering) -> i32

See the inherent fetch_or method.

Source§

fn fetch_xor(&self, val: i32, order: Ordering) -> i32

See the inherent fetch_xor method.

Source§

fn as_ptr(&self) -> *mut i32

See the inherent as_ptr method.

Source§

type Value = i32

Source§

fn store(&self, value: i32, order: Ordering)

Source§

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

Source§

impl PrimitiveAtomic for AtomicI64

Source§

fn new(value: i64) -> Self

See the inherent new method.

Source§

fn get_mut(&mut self) -> &mut i64

See the inherent get_mut method.

Source§

fn into_inner(self) -> i64

See the inherent into_inner method.

Source§

fn load(&self, order: Ordering) -> i64

See the inherent load method.

Source§

fn swap(&self, value: i64, order: Ordering) -> i64

See the inherent swap method.

Source§

fn compare_exchange( &self, current: i64, new: i64, success: Ordering, failure: Ordering, ) -> Result<i64, i64>

See the inherent compare_exchange method.

Source§

fn compare_exchange_weak( &self, current: i64, new: i64, success: Ordering, failure: Ordering, ) -> Result<i64, i64>

See the inherent compare_exchange_weak method.

Source§

fn fetch_and(&self, val: i64, order: Ordering) -> i64

See the inherent fetch_and method.

Source§

fn fetch_nand(&self, val: i64, order: Ordering) -> i64

See the inherent fetch_nand method.

Source§

fn fetch_or(&self, val: i64, order: Ordering) -> i64

See the inherent fetch_or method.

Source§

fn fetch_xor(&self, val: i64, order: Ordering) -> i64

See the inherent fetch_xor method.

Source§

fn as_ptr(&self) -> *mut i64

See the inherent as_ptr method.

Source§

type Value = i64

Source§

fn store(&self, value: i64, order: Ordering)

Source§

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

Source§

impl PrimitiveAtomic for AtomicIsize

Source§

fn new(value: isize) -> Self

See the inherent new method.

Source§

fn get_mut(&mut self) -> &mut isize

See the inherent get_mut method.

Source§

fn into_inner(self) -> isize

See the inherent into_inner method.

Source§

fn load(&self, order: Ordering) -> isize

See the inherent load method.

Source§

fn swap(&self, value: isize, order: Ordering) -> isize

See the inherent swap method.

Source§

fn compare_exchange( &self, current: isize, new: isize, success: Ordering, failure: Ordering, ) -> Result<isize, isize>

See the inherent compare_exchange method.

Source§

fn compare_exchange_weak( &self, current: isize, new: isize, success: Ordering, failure: Ordering, ) -> Result<isize, isize>

See the inherent compare_exchange_weak method.

Source§

fn fetch_and(&self, val: isize, order: Ordering) -> isize

See the inherent fetch_and method.

Source§

fn fetch_nand(&self, val: isize, order: Ordering) -> isize

See the inherent fetch_nand method.

Source§

fn fetch_or(&self, val: isize, order: Ordering) -> isize

See the inherent fetch_or method.

Source§

fn fetch_xor(&self, val: isize, order: Ordering) -> isize

See the inherent fetch_xor method.

Source§

fn as_ptr(&self) -> *mut isize

See the inherent as_ptr method.

Source§

type Value = isize

Source§

fn store(&self, value: isize, order: Ordering)

Source§

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

Source§

impl PrimitiveAtomic for AtomicU8

Source§

fn new(value: u8) -> Self

See the inherent new method.

Source§

fn get_mut(&mut self) -> &mut u8

See the inherent get_mut method.

Source§

fn into_inner(self) -> u8

See the inherent into_inner method.

Source§

fn load(&self, order: Ordering) -> u8

See the inherent load method.

Source§

fn swap(&self, value: u8, order: Ordering) -> u8

See the inherent swap method.

Source§

fn compare_exchange( &self, current: u8, new: u8, success: Ordering, failure: Ordering, ) -> Result<u8, u8>

See the inherent compare_exchange method.

Source§

fn compare_exchange_weak( &self, current: u8, new: u8, success: Ordering, failure: Ordering, ) -> Result<u8, u8>

See the inherent compare_exchange_weak method.

Source§

fn fetch_and(&self, val: u8, order: Ordering) -> u8

See the inherent fetch_and method.

Source§

fn fetch_nand(&self, val: u8, order: Ordering) -> u8

See the inherent fetch_nand method.

Source§

fn fetch_or(&self, val: u8, order: Ordering) -> u8

See the inherent fetch_or method.

Source§

fn fetch_xor(&self, val: u8, order: Ordering) -> u8

See the inherent fetch_xor method.

Source§

fn as_ptr(&self) -> *mut u8

See the inherent as_ptr method.

Source§

type Value = u8

Source§

fn store(&self, value: u8, order: Ordering)

Source§

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

Source§

impl PrimitiveAtomic for AtomicU16

Source§

fn new(value: u16) -> Self

See the inherent new method.

Source§

fn get_mut(&mut self) -> &mut u16

See the inherent get_mut method.

Source§

fn into_inner(self) -> u16

See the inherent into_inner method.

Source§

fn load(&self, order: Ordering) -> u16

See the inherent load method.

Source§

fn swap(&self, value: u16, order: Ordering) -> u16

See the inherent swap method.

Source§

fn compare_exchange( &self, current: u16, new: u16, success: Ordering, failure: Ordering, ) -> Result<u16, u16>

See the inherent compare_exchange method.

Source§

fn compare_exchange_weak( &self, current: u16, new: u16, success: Ordering, failure: Ordering, ) -> Result<u16, u16>

See the inherent compare_exchange_weak method.

Source§

fn fetch_and(&self, val: u16, order: Ordering) -> u16

See the inherent fetch_and method.

Source§

fn fetch_nand(&self, val: u16, order: Ordering) -> u16

See the inherent fetch_nand method.

Source§

fn fetch_or(&self, val: u16, order: Ordering) -> u16

See the inherent fetch_or method.

Source§

fn fetch_xor(&self, val: u16, order: Ordering) -> u16

See the inherent fetch_xor method.

Source§

fn as_ptr(&self) -> *mut u16

See the inherent as_ptr method.

Source§

type Value = u16

Source§

fn store(&self, value: u16, order: Ordering)

Source§

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

Source§

impl PrimitiveAtomic for AtomicU32

Source§

fn new(value: u32) -> Self

See the inherent new method.

Source§

fn get_mut(&mut self) -> &mut u32

See the inherent get_mut method.

Source§

fn into_inner(self) -> u32

See the inherent into_inner method.

Source§

fn load(&self, order: Ordering) -> u32

See the inherent load method.

Source§

fn swap(&self, value: u32, order: Ordering) -> u32

See the inherent swap method.

Source§

fn compare_exchange( &self, current: u32, new: u32, success: Ordering, failure: Ordering, ) -> Result<u32, u32>

See the inherent compare_exchange method.

Source§

fn compare_exchange_weak( &self, current: u32, new: u32, success: Ordering, failure: Ordering, ) -> Result<u32, u32>

See the inherent compare_exchange_weak method.

Source§

fn fetch_and(&self, val: u32, order: Ordering) -> u32

See the inherent fetch_and method.

Source§

fn fetch_nand(&self, val: u32, order: Ordering) -> u32

See the inherent fetch_nand method.

Source§

fn fetch_or(&self, val: u32, order: Ordering) -> u32

See the inherent fetch_or method.

Source§

fn fetch_xor(&self, val: u32, order: Ordering) -> u32

See the inherent fetch_xor method.

Source§

fn as_ptr(&self) -> *mut u32

See the inherent as_ptr method.

Source§

type Value = u32

Source§

fn store(&self, value: u32, order: Ordering)

Source§

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

Source§

impl PrimitiveAtomic for AtomicU64

Source§

fn new(value: u64) -> Self

See the inherent new method.

Source§

fn get_mut(&mut self) -> &mut u64

See the inherent get_mut method.

Source§

fn into_inner(self) -> u64

See the inherent into_inner method.

Source§

fn load(&self, order: Ordering) -> u64

See the inherent load method.

Source§

fn swap(&self, value: u64, order: Ordering) -> u64

See the inherent swap method.

Source§

fn compare_exchange( &self, current: u64, new: u64, success: Ordering, failure: Ordering, ) -> Result<u64, u64>

See the inherent compare_exchange method.

Source§

fn compare_exchange_weak( &self, current: u64, new: u64, success: Ordering, failure: Ordering, ) -> Result<u64, u64>

See the inherent compare_exchange_weak method.

Source§

fn fetch_and(&self, val: u64, order: Ordering) -> u64

See the inherent fetch_and method.

Source§

fn fetch_nand(&self, val: u64, order: Ordering) -> u64

See the inherent fetch_nand method.

Source§

fn fetch_or(&self, val: u64, order: Ordering) -> u64

See the inherent fetch_or method.

Source§

fn fetch_xor(&self, val: u64, order: Ordering) -> u64

See the inherent fetch_xor method.

Source§

fn as_ptr(&self) -> *mut u64

See the inherent as_ptr method.

Source§

type Value = u64

Source§

fn store(&self, value: u64, order: Ordering)

Source§

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

Source§

impl PrimitiveAtomic for AtomicUsize

Source§

fn new(value: usize) -> Self

See the inherent new method.

Source§

fn get_mut(&mut self) -> &mut usize

See the inherent get_mut method.

Source§

fn into_inner(self) -> usize

See the inherent into_inner method.

Source§

fn load(&self, order: Ordering) -> usize

See the inherent load method.

Source§

fn swap(&self, value: usize, order: Ordering) -> usize

See the inherent swap method.

Source§

fn compare_exchange( &self, current: usize, new: usize, success: Ordering, failure: Ordering, ) -> Result<usize, usize>

See the inherent compare_exchange method.

Source§

fn compare_exchange_weak( &self, current: usize, new: usize, success: Ordering, failure: Ordering, ) -> Result<usize, usize>

See the inherent compare_exchange_weak method.

Source§

fn fetch_and(&self, val: usize, order: Ordering) -> usize

See the inherent fetch_and method.

Source§

fn fetch_nand(&self, val: usize, order: Ordering) -> usize

See the inherent fetch_nand method.

Source§

fn fetch_or(&self, val: usize, order: Ordering) -> usize

See the inherent fetch_or method.

Source§

fn fetch_xor(&self, val: usize, order: Ordering) -> usize

See the inherent fetch_xor method.

Source§

fn as_ptr(&self) -> *mut usize

See the inherent as_ptr method.

Source§

type Value = usize

Source§

fn store(&self, value: usize, order: Ordering)

Source§

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

Implementors§