#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

#159 in Concurrency

Download history 3223/week @ 2024-09-20 2013/week @ 2024-09-27 2740/week @ 2024-10-04 2641/week @ 2024-10-11 3916/week @ 2024-10-18 3856/week @ 2024-10-25 4136/week @ 2024-11-01 3685/week @ 2024-11-08 4180/week @ 2024-11-15 4321/week @ 2024-11-22 2584/week @ 2024-11-29 2465/week @ 2024-12-06 3146/week @ 2024-12-13 1854/week @ 2024-12-20 1051/week @ 2024-12-27 3921/week @ 2025-01-03

10,407 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
~21K SLoC