Trait nucleic_acid::ReprUsize
[−]
[src]
pub trait ReprUsize { fn from_usize(_: usize) -> Self; fn into_usize(self) -> usize; }
A trait for representing types as usize
(useful for enums).
Note that this should be implemented for types that need to be passed to BitsVec
.
This is implemented for integer types, bool
and char
by default.
use nucleic_acid::ReprUsize; enum Foo { One, Two, } impl ReprUsize for Foo { fn into_usize(self) -> usize { match self { Foo::One => 0, Foo::Two => 1, } } fn from_usize(i: usize) -> Foo { match i { 0 => Foo::One, 1 => Foo::Two, _ => unimplemented!(), } } }
Required Methods
fn from_usize(_: usize) -> Self
Convert the value back from usize
fn into_usize(self) -> usize
Convert the value into an usize