#enums #atomic #c-style #attributes #operations #create #store

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

#205 in Concurrency

Download history 3318/week @ 2024-07-21 2812/week @ 2024-07-28 3244/week @ 2024-08-04 3013/week @ 2024-08-11 4347/week @ 2024-08-18 3939/week @ 2024-08-25 4200/week @ 2024-09-01 4736/week @ 2024-09-08 3384/week @ 2024-09-15 4208/week @ 2024-09-22 4011/week @ 2024-09-29 4069/week @ 2024-10-06 4631/week @ 2024-10-13 4312/week @ 2024-10-20 4640/week @ 2024-10-27 5541/week @ 2024-11-03

19,475 downloads per month
Used in 27 crates (14 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

~245–700KB
~17K SLoC