#enums #portable-atomic #atomic

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

#642 in Concurrency

Download history 5428/week @ 2026-02-16 6322/week @ 2026-02-23 6608/week @ 2026-03-02 5959/week @ 2026-03-09 5926/week @ 2026-03-16 5364/week @ 2026-03-23 5202/week @ 2026-03-30 5258/week @ 2026-04-06 5475/week @ 2026-04-13 5348/week @ 2026-04-20 5927/week @ 2026-04-27 6189/week @ 2026-05-04 5346/week @ 2026-05-11 5912/week @ 2026-05-18 6574/week @ 2026-05-25 5978/week @ 2026-06-01

24,462 downloads per month
Used in 14 crates (2 directly)

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

~105–730KB
~16K SLoC