#[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
use near_sdk::{BorshStorageKey, collections::Vector, near};
#[near(serializers=[borsh])]
#[derive(BorshStorageKey)]
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)
}
}
}