#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

#207 in Concurrency

Download history 3041/week @ 2024-08-12 4408/week @ 2024-08-19 3898/week @ 2024-08-26 4199/week @ 2024-09-02 4655/week @ 2024-09-09 3419/week @ 2024-09-16 4258/week @ 2024-09-23 4067/week @ 2024-09-30 3997/week @ 2024-10-07 4751/week @ 2024-10-14 4248/week @ 2024-10-21 4644/week @ 2024-10-28 5486/week @ 2024-11-04 4908/week @ 2024-11-11 5196/week @ 2024-11-18 4549/week @ 2024-11-25

20,404 downloads per month
Used in 39 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

~230–670KB
~16K SLoC