#enums #atomic #attributes #wrapper #c-style #create #value

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

#182 in Concurrency

Download history 1952/week @ 2023-12-22 2504/week @ 2023-12-29 4049/week @ 2024-01-05 3118/week @ 2024-01-12 4041/week @ 2024-01-19 3883/week @ 2024-01-26 3332/week @ 2024-02-02 3281/week @ 2024-02-09 3559/week @ 2024-02-16 3457/week @ 2024-02-23 3574/week @ 2024-03-01 3905/week @ 2024-03-08 2878/week @ 2024-03-15 3044/week @ 2024-03-22 3054/week @ 2024-03-29 2580/week @ 2024-04-05

12,249 downloads per month
Used in 18 crates (11 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

~320–770KB
~18K SLoC