Derive Macro proc_bitfield::ConvRaw

source ·
#[derive(ConvRaw)]
Expand description

A derive macro to implement any applicable conversion traits between an enum and the builtin integer types corresponding to variant discriminants.

§Usage example

(Generated type docs)

#[derive(ConvRaw)]
pub enum ConvRawExample {
    A,
    B = 2,
    C,
    D = -1,
    E = 1,
    F = -128,
    G = 128,
}

This will implement:

  • TryFrom<T> for ConvRawExample for all integer types T
  • UnsafeFrom<T> for ConvRawExample for all integer types T
  • From<ConvRawExample> for T for all integer types T that contain all discriminants; in this case, all signed integer types with >= 16 bits (i16, i32, i64, i128)