Trait rin::util::CLike [−][src]
pub trait CLike { pub fn to_usize(&self) -> usize; pub fn from_usize(u: usize) -> Self; }
An interface for casting C-like enum to usize and back. A typically implementation is as below.
ⓘ
#[repr(usize)] enum Foo { A, B, C } impl CLike for Foo { fn to_usize(&self) -> usize { *self as usize } fn from_usize(v: usize) -> Foo { unsafe { mem::transmute(v) } } }
Required methods
pub fn to_usize(&self) -> usize
[src]
Converts a C-like enum to a usize
.
pub fn from_usize(u: usize) -> Self
[src]
Converts a usize
to a C-like enum.