#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

#176 in Concurrency

Download history 3922/week @ 2024-01-03 3423/week @ 2024-01-10 3864/week @ 2024-01-17 3732/week @ 2024-01-24 3433/week @ 2024-01-31 3467/week @ 2024-02-07 3160/week @ 2024-02-14 3851/week @ 2024-02-21 3357/week @ 2024-02-28 3873/week @ 2024-03-06 3322/week @ 2024-03-13 2851/week @ 2024-03-20 3170/week @ 2024-03-27 2778/week @ 2024-04-03 2619/week @ 2024-04-10 2305/week @ 2024-04-17

11,431 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

~305–760KB
~18K SLoC