pub unsafe trait BitstructFromValue {
type StoreType;
const BIT_WIDTH: u32;
// Required method
unsafe fn from_value(value: Self::StoreType) -> Self;
}Expand description
A trait that must be implemented for non-inline field enum types. 非内联的字段枚举类型必须实现的trait。
It is recommended to use the bitstruct_field_enum macro to generate non-inline field enum types instead of implementing them manually.
推荐使用bitstruct_field_enum宏来生成非内联的字段枚举类型。而不是手动实现。
use bitstructs::{bitstruct_field_enum};
#[bitstruct_field_enum(2)]
pub enum TwoBitEnum {
Zero = 0,
One = 1,
Two = 2,
Three = 3,
}§Safety
-
Must be able to handle all values from
0to2.pow(BIT_WIDTH) - 1. -
Must implement both
BitstructToValueandBitstructFromValue. -
The
StoreTypemust be the smallest unsigned integer type that can contain all possible values, which can be one ofu8,u16,u32,u64, oru128. -
The operations of
BitstructFromValue::from_valueandBitstructToValue::to_valuemust be inverse of each other. -
The
BIT_WIDTHofBitstructFromValueandBitstructToValuemust be the same. -
必须能处理 0 到
2.pow(BIT_WIDTH) - 1的所有取值。 -
BitstructFromValue::from_value和BitstructToValue::to_value必须是互为逆操作。 -
BitstructFromValue和BitstructToValue的BIT_WIDTH必须相同。
Required Associated Constants§
Required Associated Types§
Required Methods§
unsafe fn from_value(value: Self::StoreType) -> Self
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.