Trait enum_set::CLike [] [src]

pub trait CLike {
    fn to_u32(&self) -> u32;
unsafe fn from_u32(_: u32) -> Self; }

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

Converts a C-like enum to a u32. The value must be <= 31.

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.

Implementors