#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

#226 in Concurrency

Download history 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 4637/week @ 2024-10-27 5538/week @ 2024-11-03 4768/week @ 2024-11-10 5323/week @ 2024-11-17 4750/week @ 2024-11-24 5571/week @ 2024-12-01 7088/week @ 2024-12-08 6175/week @ 2024-12-15 3245/week @ 2024-12-22 3621/week @ 2024-12-29 5246/week @ 2025-01-05

18,754 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

~235–680KB
~16K SLoC