atomic_enum 0.1.1

An attribute to create an atomic wrapper around a C-style enum
Documentation

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.