Attribute Macro atomic_enum::atomic_enum

source ·
#[atomic_enum]
Expand description

Creates an atomic wrapper around a C-style enum.

The generated type is a wrapper around AtomicUsize that transparently converts between the stores integer and the enum type. This attribute also automatically derives the Debug, Copy and Clone traits on the enum type.

The name of the atomic type is the name of the enum type, prefixed with Atomic.

#[atomic_enum]
enum State {
    On,
    Off,
}

let state = AtomicState::new(State::Off);

The name can be overridden by passing an identifier as an argument to the attribute.

#[atomic_enum(StateAtomic)]
enum State {
    On,
    Off,
}

let state = StateAtomic::new(State::Off);