[−][src]Trait enum_set::CLike
An interface for casting C-like enum to u32
and back.
The returned value must be no more than 31: EnumSet
does not support more cases than this.
A typical implementation can be seen below:
use enum_set::CLike; use std::mem; #[derive(Clone, Copy)] #[repr(u32)] enum Foo { A, B, C } impl CLike for Foo { fn to_u32(&self) -> u32 { *self as u32 } unsafe fn from_u32(v: u32) -> Foo { mem::transmute(v) } }
Required methods
fn to_u32(&self) -> u32
Converts a C-like enum to a u32
. The value must be <= 31
.
unsafe fn from_u32(_: u32) -> Self
Converts a u32
to a C-like enum. This method only needs to be safe
for possible return values of to_u32
of this trait.