Derive Macro proc_bitfield::UnwrapBitRange

source ·
#[derive(UnwrapBitRange)]
Available on crate feature nightly only.
Expand description

A derive macro to implement BitRange<T> for U for a type T and all integer bitfield storage types U, by unwrapping the conversion results.

§Usage example

(Generated type docs)

#[derive(UnwrapBitRange)]
pub struct U8(u8);

impl TryFrom<u16> for U8 {
    /* ... */
}
impl From<U8> for u16 {
    /* ... */
}

This will implement BitRange<U8> for u16, allowing it to be used as a field inside any bitfield using a u16 as its storage type, and unwrapping the result on reads.

This derive is especially useful when combined with ConvRaw, in which case it will allow enums to be used as bitfield fields, unwrapping the results of trying to convert the raw value back to an enum variant.