pub unsafe trait AsPackedValue: Sized {
const MIN_BIT_WIDTH: usize;
// Required methods
fn encode(zelf: Self) -> TruncatedU64<Self>;
unsafe fn decode(raw: TruncatedU64<Self>) -> Self;
// Provided method
fn is_rt_safe() -> bool { ... }
}Expand description
This trait is used to store the value in a Slot.
The slot may truncate the value to MIN_BIT_WIDTH bits.
Types implementing AsPackedValue may be stored in slots with MAX_CARGO_BIT_WIDTH >= MIN_BIT_WIDTH. This will be checked at compile time.
MIN_BIT_WIDTH cannot be larger than 64
§SAFETY
- both
decodeandencodemust be atomic and non-blocking decodemust only be called on a value returned byencode- the encoded value must be reconstructable fully from the lower
MIN_BIT_WIDTHbits
Required Associated Constants§
Sourceconst MIN_BIT_WIDTH: usize
const MIN_BIT_WIDTH: usize
The minimal bit width from which this type may be reconstructed.
Required Methods§
Sourcefn encode(zelf: Self) -> TruncatedU64<Self>
fn encode(zelf: Self) -> TruncatedU64<Self>
Truncates Self to the lower MIN_BIT_WIDTH bits.
The caller is responsible for reconstructing this value usign decode
Sourceunsafe fn decode(raw: TruncatedU64<Self>) -> Self
unsafe fn decode(raw: TruncatedU64<Self>) -> Self
Reconstructs Self from the lower MIN_BIT_WIDTH bits returned by encode.
§SAFETY
The caller must ensure that the passed value is a valid value returned by encode
Provided Methods§
Sourcefn is_rt_safe() -> bool
fn is_rt_safe() -> bool
Validates wether self is actually safe to pack into Self::MIN_BIT_WIDTH bits at runtime.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".