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, AtomicUsize, AtomicI8,
AtomicI16, AtomicI32, AtomicIsize, and, on targets with
64-bit atomics, AtomicU64 and AtomicI64.
See the corresponding items on the individual types for more documentation and examples.
This trait is sealed to prevent downstream implementations.
Required Associated Types§
Sourcetype Value: Copy + Send + Sync + AtomicPrimitive<Atomic = Self>
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§
Sourcefn into_inner(self) -> Self::Value
fn into_inner(self) -> Self::Value
Consumes the atomic and returns the contained value.
Sourcefn swap(&self, value: Self::Value, order: Ordering) -> Self::Value
fn swap(&self, value: Self::Value, order: Ordering) -> Self::Value
Stores a value into the atomic, returning the previous value.
Sourcefn compare_exchange(
&self,
current: Self::Value,
new: Self::Value,
success: Ordering,
failure: Ordering,
) -> Result<Self::Value, Self::Value>
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.
Sourcefn compare_exchange_weak(
&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>
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.
Sourcefn fetch_update<F>(
&self,
set_order: Ordering,
fetch_order: Ordering,
f: F,
) -> Result<Self::Value, Self::Value>
fn fetch_update<F>( &self, set_order: Ordering, fetch_order: Ordering, f: F, ) -> Result<Self::Value, 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).
Sourcefn fetch_and(&self, val: Self::Value, order: Ordering) -> Self::Value
fn fetch_and(&self, val: Self::Value, order: Ordering) -> Self::Value
Bitwise “and” with the current value. Returns the previous value.
Sourcefn fetch_nand(&self, val: Self::Value, order: Ordering) -> Self::Value
fn fetch_nand(&self, val: Self::Value, order: Ordering) -> Self::Value
Bitwise “nand” with the current value. Returns the previous value.
Sourcefn fetch_or(&self, val: Self::Value, order: Ordering) -> Self::Value
fn fetch_or(&self, val: Self::Value, order: Ordering) -> Self::Value
Bitwise “or” with the current value. Returns the previous 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
impl PrimitiveAtomic for AtomicBool
Source§fn into_inner(self) -> bool
fn into_inner(self) -> bool
See the inherent into_inner method.
Source§fn compare_exchange(
&self,
current: bool,
new: bool,
success: Ordering,
failure: Ordering,
) -> Result<bool, bool>
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>
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_nand(&self, val: bool, order: Ordering) -> bool
fn fetch_nand(&self, val: bool, order: Ordering) -> bool
See the inherent fetch_nand method.
type Value = bool
fn store(&self, value: bool, order: Ordering)
fn fetch_update<F>( &self, set_order: Ordering, fetch_order: Ordering, f: F, ) -> Result<bool, bool>
Source§impl PrimitiveAtomic for AtomicI8
impl PrimitiveAtomic for AtomicI8
Source§fn into_inner(self) -> i8
fn into_inner(self) -> i8
See the inherent into_inner method.
Source§fn compare_exchange(
&self,
current: i8,
new: i8,
success: Ordering,
failure: Ordering,
) -> Result<i8, i8>
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>
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_nand(&self, val: i8, order: Ordering) -> i8
fn fetch_nand(&self, val: i8, order: Ordering) -> i8
See the inherent fetch_nand method.
type Value = i8
fn store(&self, value: i8, order: Ordering)
fn fetch_update<F>( &self, set_order: Ordering, fetch_order: Ordering, f: F, ) -> Result<i8, i8>
Source§impl PrimitiveAtomic for AtomicI16
impl PrimitiveAtomic for AtomicI16
Source§fn into_inner(self) -> i16
fn into_inner(self) -> i16
See the inherent into_inner method.
Source§fn compare_exchange(
&self,
current: i16,
new: i16,
success: Ordering,
failure: Ordering,
) -> Result<i16, i16>
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>
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_nand(&self, val: i16, order: Ordering) -> i16
fn fetch_nand(&self, val: i16, order: Ordering) -> i16
See the inherent fetch_nand method.
type Value = i16
fn store(&self, value: i16, order: Ordering)
fn fetch_update<F>( &self, set_order: Ordering, fetch_order: Ordering, f: F, ) -> Result<i16, i16>
Source§impl PrimitiveAtomic for AtomicI32
impl PrimitiveAtomic for AtomicI32
Source§fn into_inner(self) -> i32
fn into_inner(self) -> i32
See the inherent into_inner method.
Source§fn compare_exchange(
&self,
current: i32,
new: i32,
success: Ordering,
failure: Ordering,
) -> Result<i32, i32>
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>
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_nand(&self, val: i32, order: Ordering) -> i32
fn fetch_nand(&self, val: i32, order: Ordering) -> i32
See the inherent fetch_nand method.
type Value = i32
fn store(&self, value: i32, order: Ordering)
fn fetch_update<F>( &self, set_order: Ordering, fetch_order: Ordering, f: F, ) -> Result<i32, i32>
Source§impl PrimitiveAtomic for AtomicI64
impl PrimitiveAtomic for AtomicI64
Source§fn into_inner(self) -> i64
fn into_inner(self) -> i64
See the inherent into_inner method.
Source§fn compare_exchange(
&self,
current: i64,
new: i64,
success: Ordering,
failure: Ordering,
) -> Result<i64, i64>
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>
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_nand(&self, val: i64, order: Ordering) -> i64
fn fetch_nand(&self, val: i64, order: Ordering) -> i64
See the inherent fetch_nand method.
type Value = i64
fn store(&self, value: i64, order: Ordering)
fn fetch_update<F>( &self, set_order: Ordering, fetch_order: Ordering, f: F, ) -> Result<i64, i64>
Source§impl PrimitiveAtomic for AtomicIsize
impl PrimitiveAtomic for AtomicIsize
Source§fn into_inner(self) -> isize
fn into_inner(self) -> isize
See the inherent into_inner method.
Source§fn compare_exchange(
&self,
current: isize,
new: isize,
success: Ordering,
failure: Ordering,
) -> Result<isize, isize>
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>
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_nand(&self, val: isize, order: Ordering) -> isize
fn fetch_nand(&self, val: isize, order: Ordering) -> isize
See the inherent fetch_nand method.
type Value = isize
fn store(&self, value: isize, order: Ordering)
fn fetch_update<F>( &self, set_order: Ordering, fetch_order: Ordering, f: F, ) -> Result<isize, isize>
Source§impl PrimitiveAtomic for AtomicU8
impl PrimitiveAtomic for AtomicU8
Source§fn into_inner(self) -> u8
fn into_inner(self) -> u8
See the inherent into_inner method.
Source§fn compare_exchange(
&self,
current: u8,
new: u8,
success: Ordering,
failure: Ordering,
) -> Result<u8, u8>
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>
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_nand(&self, val: u8, order: Ordering) -> u8
fn fetch_nand(&self, val: u8, order: Ordering) -> u8
See the inherent fetch_nand method.
type Value = u8
fn store(&self, value: u8, order: Ordering)
fn fetch_update<F>( &self, set_order: Ordering, fetch_order: Ordering, f: F, ) -> Result<u8, u8>
Source§impl PrimitiveAtomic for AtomicU16
impl PrimitiveAtomic for AtomicU16
Source§fn into_inner(self) -> u16
fn into_inner(self) -> u16
See the inherent into_inner method.
Source§fn compare_exchange(
&self,
current: u16,
new: u16,
success: Ordering,
failure: Ordering,
) -> Result<u16, u16>
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>
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_nand(&self, val: u16, order: Ordering) -> u16
fn fetch_nand(&self, val: u16, order: Ordering) -> u16
See the inherent fetch_nand method.
type Value = u16
fn store(&self, value: u16, order: Ordering)
fn fetch_update<F>( &self, set_order: Ordering, fetch_order: Ordering, f: F, ) -> Result<u16, u16>
Source§impl PrimitiveAtomic for AtomicU32
impl PrimitiveAtomic for AtomicU32
Source§fn into_inner(self) -> u32
fn into_inner(self) -> u32
See the inherent into_inner method.
Source§fn compare_exchange(
&self,
current: u32,
new: u32,
success: Ordering,
failure: Ordering,
) -> Result<u32, u32>
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>
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_nand(&self, val: u32, order: Ordering) -> u32
fn fetch_nand(&self, val: u32, order: Ordering) -> u32
See the inherent fetch_nand method.
type Value = u32
fn store(&self, value: u32, order: Ordering)
fn fetch_update<F>( &self, set_order: Ordering, fetch_order: Ordering, f: F, ) -> Result<u32, u32>
Source§impl PrimitiveAtomic for AtomicU64
impl PrimitiveAtomic for AtomicU64
Source§fn into_inner(self) -> u64
fn into_inner(self) -> u64
See the inherent into_inner method.
Source§fn compare_exchange(
&self,
current: u64,
new: u64,
success: Ordering,
failure: Ordering,
) -> Result<u64, u64>
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>
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_nand(&self, val: u64, order: Ordering) -> u64
fn fetch_nand(&self, val: u64, order: Ordering) -> u64
See the inherent fetch_nand method.
type Value = u64
fn store(&self, value: u64, order: Ordering)
fn fetch_update<F>( &self, set_order: Ordering, fetch_order: Ordering, f: F, ) -> Result<u64, u64>
Source§impl PrimitiveAtomic for AtomicUsize
impl PrimitiveAtomic for AtomicUsize
Source§fn into_inner(self) -> usize
fn into_inner(self) -> usize
See the inherent into_inner method.
Source§fn compare_exchange(
&self,
current: usize,
new: usize,
success: Ordering,
failure: Ordering,
) -> Result<usize, usize>
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>
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_nand(&self, val: usize, order: Ordering) -> usize
fn fetch_nand(&self, val: usize, order: Ordering) -> usize
See the inherent fetch_nand method.