Packable

Trait Packable 

Source
pub trait Packable: OnlyPrimitives + StorableType {
    // Required methods
    fn to_word(&self) -> U256;
    fn from_word(word: U256) -> Result<Self>
       where Self: Sized;
}
Expand description

Trait for types that can be packed into EVM storage slots.

This trait is sealed - it can only be implemented within this crate for primitive types that fit in a single U256 word.

§Usage

Packable is used by the storage packing system to efficiently pack multiple small values into a single 32-byte storage slot.

§Safety

Implementations must ensure:

  • IS_PACKABLE is true for the implementing type (enforced at compile time)
  • Round-trip conversions preserve data: from_word(to_word(x)) == x

Required Methods§

Source

fn to_word(&self) -> U256

Encode this type to a single U256 word.

Source

fn from_word(word: U256) -> Result<Self>
where Self: Sized,

Decode this type from a single U256 word.

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.

Implementations on Foreign Types§

Source§

impl Packable for bool

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for i8

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for i16

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for i32

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for i64

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for i128

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for u8

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for u16

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for u32

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for u64

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for u128

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for Address

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<1usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<2usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<3usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<4usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<5usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<6usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<7usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<8usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<9usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<10usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<11usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<12usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<13usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<14usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<15usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<16usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<17usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<18usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<19usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<20usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<21usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<22usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<23usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<24usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<25usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<26usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<27usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<28usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<29usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<30usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<31usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for FixedBytes<32usize>

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for I8

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for I16

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for I32

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for I64

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for I128

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for I256

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for U8

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for U16

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for U32

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for U64

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for U128

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Source§

impl Packable for U256

Source§

fn to_word(&self) -> U256

Source§

fn from_word(word: U256) -> Result<Self>

Implementors§