portable_atomic_enum

Crates.ioportable_atomic_enum
lib.rsportable_atomic_enum
version0.3.1
sourcesrc
created_at2023-10-18 11:00:31.939175
updated_at2024-03-03 15:29:40.027359
descriptionAn attribute to create an portable atomic wrapper around a C-style enum
homepage
repositoryhttps://github.com/bugadani/portable_atomic_enum
max_upload_size
id1006598
size6,030
Dániel Buga (bugadani)

documentation

README

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
Commit count: 27

cargo fmt