#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

#219 in Concurrency

Download history 4592/week @ 2024-09-03 4435/week @ 2024-09-10 3275/week @ 2024-09-17 4370/week @ 2024-09-24 4155/week @ 2024-10-01 3873/week @ 2024-10-08 4902/week @ 2024-10-15 4279/week @ 2024-10-22 4973/week @ 2024-10-29 5046/week @ 2024-11-05 5173/week @ 2024-11-12 4981/week @ 2024-11-19 4888/week @ 2024-11-26 6168/week @ 2024-12-03 7005/week @ 2024-12-10 4956/week @ 2024-12-17

23,706 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

~225–660KB
~16K SLoC