#enums #atomic #c-style #attributes #store #value #sync

macro atomic_enum

An attribute to create an atomic wrapper around a C-style enum

4 releases (2 breaking)

0.3.0 Feb 21, 2024
0.2.0 Jul 25, 2022
0.1.1 Mar 9, 2020
0.1.0 Dec 6, 2018

#328 in Concurrency

Download history 5693/week @ 2024-12-02 7139/week @ 2024-12-09 6083/week @ 2024-12-16 3261/week @ 2024-12-23 3623/week @ 2024-12-30 5722/week @ 2025-01-06 5874/week @ 2025-01-13 5896/week @ 2025-01-20 5728/week @ 2025-01-27 6644/week @ 2025-02-03 7199/week @ 2025-02-10 6149/week @ 2025-02-17 7441/week @ 2025-02-24 7099/week @ 2025-03-03 7237/week @ 2025-03-10 6931/week @ 2025-03-17

29,117 downloads per month
Used in 40 crates (15 directly)

MIT license

20KB
297 lines

cargo version docs.rs version

atomic_enum

An attribute to create an atomic wrapper around a C-style enum.

Internally, the generated wrapper uses an AtomicUsize to store the value. The atomic operations have the same semantics as the equivalent operations of AtomicUsize.

Example

# use atomic_enum::atomic_enum;
# use std::sync::atomic::Ordering;
#[atomic_enum]
#[derive(PartialEq)]
enum CatState {
    Dead = 0,
    BothDeadAndAlive,
    Alive,
}

let state = AtomicCatState::new(CatState::Dead);
state.store(CatState::Alive, Ordering::Relaxed);
assert_eq!(state.load(Ordering::Relaxed), CatState::Alive);

This attribute does not use or generate any unsafe code.

The crate can be used in a #[no_std] environment.

Maintenance Note

This crate is passively maintained.

Dependencies

~220–660KB
~16K SLoC