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

portable_atomic_enum

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

6 releases

0.3.1 Mar 3, 2024
0.3.0 Nov 14, 2023
0.2.0 Nov 13, 2023
0.1.2 Oct 18, 2023

#173 in Concurrency

Download history 2461/week @ 2024-08-10 1850/week @ 2024-08-17 2782/week @ 2024-08-24 3613/week @ 2024-08-31 2902/week @ 2024-09-07 3447/week @ 2024-09-14 2894/week @ 2024-09-21 1977/week @ 2024-09-28 3030/week @ 2024-10-05 2449/week @ 2024-10-12 4076/week @ 2024-10-19 3618/week @ 2024-10-26 4778/week @ 2024-11-02 3299/week @ 2024-11-09 4831/week @ 2024-11-16 3047/week @ 2024-11-23

16,313 downloads per month
Used in 2 crates (via esp-wifi)

MIT license

6KB

cargo version docs.rs version

portable_atomic_enum

This crate is a fork of atomic_enum and optionally uses portable-atomic to support more targets.

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(Clone, Copy, Debug, 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.

Cargo features

  • portable-atomic: polyfill atomic types using portable-atomic

Dependencies

~0.2–1MB
~20K SLoC