Skip to main content

Crate generic_atomics

Crate generic_atomics 

Source
Expand description

§Generic Atomics

crate documentation MSRV

Generic Atomic type for types that implement num-primitive traits.

§Compatibility

The crate is tested for stable and nightly compiler.

Current MSRV is 1.97.1.

§Usage

Add this to your Cargo.toml:

[dependencies]
generic-atomics = "0.1"

§Example

use generic_atomics::{
    Atomic, IntoAtomicFloat, UseUpdateToAdd,
};
use std::sync::atomic::Ordering;

fn main() {
    let fourtytwo = 42.0f64;
    let one = 1f64;
    let af = fourtytwo.into_atomic_float();
    af.fetch_add_via_update(one, Ordering::Relaxed);
    assert_eq!(fourtytwo + one, af.load(Ordering::Relaxed));
}

§Context

This crate started from atomic_float and the code generated by the macros of atomic-traits, unlike atomic_float this provides a generic AtomicFlaot<T: PrimitiveFloat> that implements the atomic-traits.

Modules§

fetch
Fetch and apply operations to the current value, returning the previous value.

Structs§

AtomicNumber

Traits§

AsPtr
Returns a mutable pointer to the underlying type.
Atomic
Generic atomic types
AtomicFloat
Bitwise
The trait for types implementing atomic bitwise operations
FromPtr
Creates a new atomic type from a pointer.
IntoAtomicFloat
IntoAtomicInteger
IntoAtomicNumber
NumOps
The trait for types implementing atomic numeric operations
UseUpdateToAdd
UseUpdateToMax
UseUpdateToMin
UseUpdateToSub