#portable-atomic #atomic #enums #attributes #create #c-style #store

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

#4 in #portable-atomic

Download history 4832/week @ 2024-11-16 3424/week @ 2024-11-23 2848/week @ 2024-11-30 2054/week @ 2024-12-07 3903/week @ 2024-12-14 953/week @ 2024-12-21 1371/week @ 2024-12-28 4248/week @ 2025-01-04 5618/week @ 2025-01-11 3937/week @ 2025-01-18 3852/week @ 2025-01-25 4618/week @ 2025-02-01 4540/week @ 2025-02-08 3288/week @ 2025-02-15 2506/week @ 2025-02-22 2875/week @ 2025-03-01

14,282 downloads per month
Used in 4 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

~185–610KB
~14K SLoC