Derive Macro BorshStorageKey

Source
#[derive(BorshStorageKey)]
Expand description

BorshStorageKey generates implementation for BorshIntoStorageKey trait. It allows the type to be passed as a unique prefix for persistent collections. The type should also implement or derive BorshSerialize trait.

More information about storage keys in NEAR documentation

§Example

#[derive(BorshSerialize, BorshDeserialize, BorshStorageKey)]
#[borsh(crate = "near_sdk::borsh")]
pub enum StorageKey {
    Messages,
}

// Define the contract structure
#[near(contract_state)]
pub struct Contract {
    messages: Vector<String>
}

// Define the default, which automatically initializes the contract
impl Default for Contract {
    fn default() -> Self {
        Self {
            messages: Vector::new(StorageKey::Messages)
        }
    }
}