atomic_enum

Crates.ioatomic_enum
lib.rsatomic_enum
version0.3.0
sourcesrc
created_at2018-12-06 22:18:02.563972
updated_at2024-02-21 16:56:02.874321
descriptionAn attribute to create an atomic wrapper around a C-style enum
homepage
repositoryhttps://github.com/brain0/atomic_enum
max_upload_size
id100463
size21,268
(brain0)

documentation

README

cargo version docs.rs version

atomic_enum

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(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.

Maintenance Note

This crate is passively maintained.

Commit count: 17

cargo fmt