#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

#277 in Concurrency

Download history 5380/week @ 2024-11-15 5117/week @ 2024-11-22 5155/week @ 2024-11-29 6675/week @ 2024-12-06 6348/week @ 2024-12-13 3959/week @ 2024-12-20 3300/week @ 2024-12-27 5569/week @ 2025-01-03 5798/week @ 2025-01-10 5773/week @ 2025-01-17 5823/week @ 2025-01-24 6421/week @ 2025-01-31 6935/week @ 2025-02-07 6229/week @ 2025-02-14 7786/week @ 2025-02-21 6931/week @ 2025-02-28

29,336 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

~200–640KB
~15K SLoC