#atomic #enum

macro atomic_enum

An attribute to create an atomic wrapper around a C-style enum

3 unstable releases

0.2.0 Jul 25, 2022
0.1.1 Mar 9, 2020
0.1.0 Dec 6, 2018

#398 in Concurrency

Download history 1122/week @ 2023-08-07 1296/week @ 2023-08-14 1103/week @ 2023-08-21 1138/week @ 2023-08-28 944/week @ 2023-09-04 1395/week @ 2023-09-11 1583/week @ 2023-09-18 1240/week @ 2023-09-25 1583/week @ 2023-10-02 1995/week @ 2023-10-09 2142/week @ 2023-10-16 2707/week @ 2023-10-23 2870/week @ 2023-10-30 2297/week @ 2023-11-06 2061/week @ 2023-11-13 1925/week @ 2023-11-20

9,345 downloads per month
Used in 12 crates (10 directly)

MIT license

19KB
286 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

#[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.


lib.rs:

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

#[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.

Dependencies

~1MB
~31K SLoC