atomic_enum
atomic_enum copied to clipboard
Dynamically choose underlying atomic unsigned size based on enum variants count
This library uses AtomicUsize as the underlying numeric atomic size. In most cases, AtomicU8 would be possible, but it would be nice if the macro could change the underlying atomic type based on how many variants there are.
Of course, some embedded devices don't support atomic u8 or other types specifically, but this could be resolved by falling back to AtomicUsize using conditional compilation.
Eg:
#[cfg(target_has_atomic = "8")]
pub struct AtomicCatState(AtomicU8);
#[cfg(not(target_has_atomic = "8"))]
pub struct AtomicCatState(AtomicUsize);