#atomic #enums #debugging

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

#93 in #enum

Download history 23/week @ 2023-12-18 16/week @ 2023-12-25 127/week @ 2024-01-01 251/week @ 2024-01-08 141/week @ 2024-01-15 197/week @ 2024-01-22 150/week @ 2024-01-29 118/week @ 2024-02-05 296/week @ 2024-02-12 306/week @ 2024-02-19 326/week @ 2024-02-26 499/week @ 2024-03-04 1089/week @ 2024-03-11 747/week @ 2024-03-18 713/week @ 2024-03-25 575/week @ 2024-04-01

3,201 downloads per month
Used in 2 crates (via portable_atomic_enum)

MIT license

16KB
248 lines

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

lib.rs:

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

~315–770KB
~18K SLoC