Function std::storage::storage_api::write_slot
pub fn write_slot<T>(slot: b256, value: T) Expand description
Stores a value in storage in a single dynamic slot.
Additional Information
The value is entirely stored in the slot and never crosses into another slot.
If T is a zero-sized type, no storage access will occur. Storage API does not store zero-sized types in storage,
so reading from the slot and offset where a zero-sized type would be stored will return None.
The value is memory-copied into the storage slot. If it contains any pointers or references,
the data they point to will not be stored in storage.
To store dynamic types like Vec, String, or Bytes, use the dedicated storage types provided in the storage module,
like StorageVec, StorageString, and StorageBytes.
Arguments
slot: [b256] - The storage slot at which thevaluewill be stored.value: [T] - The value to be stored.
Number of Storage Accesses
- Writes:
1
Examples
use std::storage::storage_api::{read_slot, write_slot};
fn foo() {
let five = 5_u64;
write_slot(b256::zero(), five);
let stored_five = read_slot::<u64>(b256::zero(), 0).unwrap();
assert_eq(five, stored_five);
}