Expand description

Custom derive for ink_storage traits.

This crate provides helpers to define your very own custom storage data structures that work along the ink_storage data structures by implementing SpreadLayout and PackedLayout traits.

See Spread vs. Packed for more details of these two root strategies.

Examples

use ink_storage::traits::{SpreadLayout, push_spread_root};
use ink_primitives::Key;

// Enum
#[derive(SpreadLayout)]
enum Vote {
    Yes,
    No
}

// Strucut
#[derive(SpreadLayout)]
struct NamedFields {
    a: u32,
    b: [u32; 32],
};

// Created a custom structure and told which key to update.
push_spread_root(&NamedFields{ a: 123, b: [22; 32] }, &mut Key::from([0x42; 32]));

Derive Macros

Derives ink_storage’s PackedLayout trait for the given struct or enum.

Derives ink_storage’s SpreadAllocate trait for the given struct.

Derives ink_storage’s SpreadLayout trait for the given struct or enum.

Derives ink_storage’s StorageLayout trait for the given struct or enum.