Trait collections::enum_set::CLike [] [src]

pub trait CLike {
    fn to_usize(&self) -> usize;
    fn from_usize(usize) -> Self;
}
Unstable (enumset #0)

: matches collection reform specification, waiting for dust to settle

An interface for casting C-like enum to usize and back. A typically implementation is as below.

fn main() { #[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) } } } }
#[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

fn to_usize(&self) -> usize

Unstable (enumset #0)

: matches collection reform specification, waiting for dust to settle

Converts a C-like enum to a usize.

fn from_usize(usize) -> Self

Unstable (enumset #0)

: matches collection reform specification, waiting for dust to settle

Converts a usize to a C-like enum.

Implementors