Attribute Macro pendzl::storage_item

source ·
#[storage_item]
Expand description

The macro implements ink::storage_item macro for the struct, which means that it prepares your struct to be a part of contract’s storage. Also, inside of struct marked by this macro you can use #[lazy] attribute to mark fields, that should be lazily loaded and wrapped in ::ink::storage::Lazy. The macro also generates constant storage keys for every mapping or lazy field and inserts them into type definition following recomendation from https://use.ink/datastructures/storage-layout

§Example

#[pendzl::storage_item]
pub struct MyStruct {
   a: u32,
   b: u32,
}

§Example

#[pendzl::storage_item]
pub struct MyStruct {
    #[lazy]
    a: u32,
    #[lazy]
    b: u32,
}

# Example

```skip
#[pendzl::storage_item]
pub struct MyStruct {
    field: u32
    #[lazy]
    lazy_field: u32,
    mappping: Mapping<AccountId, u128>,
}

will be transformed into:

#[::ink::storage_item]
pub struct MyStruct {
   field: u32
   lazy_field: ::ink::storage::Lazy<u32, ::ink::storage::traits::ManualKey<MYSTRUCT_LAZY_FIELD_STORAGE_KEY>>,
   mappping: ::ink::storage::Lazy<Mapping<AccountId, u128>, ::ink::storage::traits::ManualKey<MYSTRUCT_MAPPING_STORAGE_KEY>>,
}
pub const MYSTRUCT_LAZY_FIELD_STORAGE_KEY: u32 = ::pendzl::storage_unique_key!(MyStruct, lazy_field);
pub const MYSTRUCT_MAPPING_STORAGE_KEY: u32 = ::pendzl::storage_unique_key!(MyStruct, mapping);