Function std::storage::storage_api::append_slot
pub fn append_slot<T>(slot: b256, value: T) Expand description
Appends a value to the end of the currently used portion of a single dynamic slot.
Additional Information
The value is stored at the end of the currently used portion of the slot and never crosses into another slot.
This is equivalent to calling update_slot with u64::max() as the offset.
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 to which thevaluewill be appended.value: [T] - The value to be appended.
Number of Storage Accesses
- Internal preloads:
1 - Writes:
1
Examples
use std::storage::storage_api::{read_slot, write_slot, append_slot};
fn foo() {
let five = 5_u64;
write_slot(b256::zero(), five);
append_slot(b256::zero(), five + 1);
append_slot(b256::zero(), five + 2);
let stored_five = read_slot::<u64>(b256::zero(), 0).unwrap();
assert_eq(five, stored_five);
let stored_six = read_slot::<u64>(b256::zero(), 1).unwrap();
assert_eq(five + 1, stored_six);
let stored_seven = read_slot::<u64>(b256::zero(), 2).unwrap();
assert_eq(five + 2, stored_seven);
}