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

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

#203 in Concurrency

Download history 167/week @ 2024-01-27 114/week @ 2024-02-03 244/week @ 2024-02-10 316/week @ 2024-02-17 267/week @ 2024-02-24 559/week @ 2024-03-02 1003/week @ 2024-03-09 781/week @ 2024-03-16 720/week @ 2024-03-23 483/week @ 2024-03-30 747/week @ 2024-04-06 690/week @ 2024-04-13 596/week @ 2024-04-20 651/week @ 2024-04-27 568/week @ 2024-05-04 752/week @ 2024-05-11

2,668 downloads per month
Used in 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.3–1MB
~22K SLoC