Derive Macro ink_storage_derive::PackedLayout
source · [−]#[derive(PackedLayout)]
Expand description
Derives ink_storage
’s PackedLayout
trait for the given struct
or enum
.
Examples
use scale::{Encode, Decode};
use ink_primitives::Key;
use ink_storage::traits::{
SpreadLayout,
PackedLayout,
push_packed_root,
pull_packed_root
};
#[derive(Encode, Decode, SpreadLayout, PackedLayout)]
struct NamedFields {
a: u32,
b: [u32; 32],
}
let mut value = NamedFields {
a: 123,
b: [22; 32],
};
push_packed_root(&value, &mut Key::from([0x42; 32]));
let value2: NamedFields = pull_packed_root(&mut Key::from([0x42; 32]));
assert_eq!(value.a, value2.a);