AtomicNumber

Trait AtomicNumber 

Source
pub trait AtomicNumber: Atomic {
    // Required methods
    fn fetch_add(&self, delta: Self::Value) -> Self::Value;
    fn fetch_sub(&self, delta: Self::Value) -> Self::Value;
    fn fetch_mul(&self, factor: Self::Value) -> Self::Value;
    fn fetch_div(&self, divisor: Self::Value) -> Self::Value;
}
Expand description

Trait for atomic numeric types that support arithmetic operations.

Provides common arithmetic operations (add, subtract, multiply, divide) for both integer and floating-point atomic types. This trait unifies the arithmetic interface across all numeric atomic types.

§Note

Integer types also provide fetch_inc() and fetch_dec() methods as convenient shortcuts for incrementing/decrementing by 1, but these are not part of this trait as they are integer-specific operations.

§Author

Haixing Hu

Required Methods§

Source

fn fetch_add(&self, delta: Self::Value) -> Self::Value

Adds a delta to the value, returning the old value.

For integers, uses Relaxed ordering by default. For floating-point types, uses AcqRel ordering (CAS loop).

§Parameters
  • delta - The value to add.
§Returns

The old value before adding.

Source

fn fetch_sub(&self, delta: Self::Value) -> Self::Value

Subtracts a delta from the value, returning the old value.

For integers, uses Relaxed ordering by default. For floating-point types, uses AcqRel ordering (CAS loop).

§Parameters
  • delta - The value to subtract.
§Returns

The old value before subtracting.

Source

fn fetch_mul(&self, factor: Self::Value) -> Self::Value

Multiplies the value by a factor, returning the old value.

Uses AcqRel ordering by default. Implemented via CAS loop.

§Parameters
  • factor - The value to multiply by.
§Returns

The old value before multiplying.

Source

fn fetch_div(&self, divisor: Self::Value) -> Self::Value

Divides the value by a divisor, returning the old value.

Uses AcqRel ordering by default. Implemented via CAS loop.

§Parameters
  • divisor - The value to divide by.
§Returns

The old value before dividing.

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.

Implementors§