#atomic #enum

atomic_enum

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

2 releases

0.1.1 Mar 9, 2020
0.1.0 Dec 6, 2018

#41 in #atomic

Download history 31/week @ 2021-06-29 21/week @ 2021-07-06 24/week @ 2021-07-13 29/week @ 2021-07-20 33/week @ 2021-07-27 69/week @ 2021-08-03 36/week @ 2021-08-10 32/week @ 2021-08-17 26/week @ 2021-08-24 5/week @ 2021-08-31 16/week @ 2021-09-07 24/week @ 2021-09-14 20/week @ 2021-09-21 67/week @ 2021-09-28 44/week @ 2021-10-05 47/week @ 2021-10-12

111 downloads per month
Used in incinerator

MIT license

17KB
289 lines


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

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

Dependencies

~310–730KB
~18K SLoC