#enums #atomic

macro portable_atomic_enum_macros

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

5 releases

0.2.1 Mar 3, 2024
0.2.0 Nov 14, 2023
0.1.2 Oct 18, 2023
0.1.1 Oct 18, 2023
0.1.0 Oct 18, 2023

#71 in #enum

Download history 1779/week @ 2024-07-21 1646/week @ 2024-07-28 1612/week @ 2024-08-04 2327/week @ 2024-08-11 1858/week @ 2024-08-18 2921/week @ 2024-08-25 3719/week @ 2024-09-01 2780/week @ 2024-09-08 3556/week @ 2024-09-15 2740/week @ 2024-09-22 1976/week @ 2024-09-29 3159/week @ 2024-10-06 2346/week @ 2024-10-13 4064/week @ 2024-10-20 3811/week @ 2024-10-27 4586/week @ 2024-11-03

15,042 downloads per month
Used in 3 crates (via portable_atomic_enum)

MIT license

16KB
248 lines

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

~245–700KB
~17K SLoC