#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

#180 in Concurrency

Download history 4165/week @ 2024-01-22 3519/week @ 2024-01-29 3366/week @ 2024-02-05 3148/week @ 2024-02-12 4057/week @ 2024-02-19 3093/week @ 2024-02-26 3737/week @ 2024-03-04 3714/week @ 2024-03-11 2781/week @ 2024-03-18 3026/week @ 2024-03-25 3236/week @ 2024-04-01 2205/week @ 2024-04-08 2976/week @ 2024-04-15 3530/week @ 2024-04-22 3329/week @ 2024-04-29 3163/week @ 2024-05-06

13,126 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

~0.3–0.8MB
~19K SLoC