Derive Macro proc_bitfield::ConvRaw
#[derive(ConvRaw)]
Expand description
A derive macro to implement any applicable conversion traits between an enum and the builtin integer and boolean types corresponding to variant discriminants.
§Usage example
/// An enum showcasing the `ConvRaw` derive for converting from/into integers.
#[derive(ConvRaw)]
pub enum ConvRawIntExample {
A,
B = 2,
C,
D = -1,
E = 1,
F = -128,
G = 128,
}
This will implement:
TryFrom<T> for ConvRawIntExample
for all integer typesT
UnsafeFrom<T> for ConvRawIntExample
for all integer typesT
From<ConvRawIntExample> for T
for all integer typesT
that contain all discriminants; in this case, all signed integer types with>= 16
bits (i16
,i32
,i64
,i128
)From<bool> for ConvRawBoolExample
From<ConvRawBoolExample> for bool
/// An enum showcasing the `ConvRaw` derive for converting from/into booleans.
#[derive(ConvRaw)]
pub enum ConvRawBoolExample {
False, // Implicitly, this value is treated as 0 (false).
True,
}
This will implement:
TryFrom<T> for ConvRawBool
for all integer typesT
UnsafeFrom<T> for ConvRawBool
for all integer typesT
From<ConvRawBool> for T
for all integer typesT
that contain all discriminants; in this case, all integer typesFrom<bool> for ConvRawBoolExample
From<ConvRawBoolExample> for bool