pub trait CLike {
// Required methods
fn to_u32(&self) -> u32;
unsafe fn from_u32(_: u32) -> Self;
}
Expand description
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§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.