pub fn write_slice(slot: b256, slice: raw_slice) 
Expand description

Stores slice into storage, in slots of 32 bytes, starting at the slot.

Deprecation Notice

This function is deprecated in favor of write_slice_quads and write_slice_slot.
To preserve exactly the same behavior as write, use write_slice_quads. To store the slice into
a single dynamic slot of a variable size, use write_slice_slot.

Additional Information

If slice is empty (i.e., has a length of zero), storage access will still occur,
but no content slots will be written to. The length of the slice in the storage will be set
to zero, but eventual existing content of the slice in storage will not be cleared.

Arguments

  • slot: [b256] - The starting storage slot at which slice will be stored.
  • slice: [raw_slice] - The raw_slice to be stored.

Number of Storage Accesses

  • Reads: 1 (to read the existing data in the slice length slot)
  • Writes: 2 (one for the length of the slice, and one for the slice content)

Examples

use std::{alloc::alloc_bytes, storage::{write_slice, read_slice}};

fn foo() {
    let slice = asm(ptr: (alloc_bytes(1), 1)) { ptr: raw_slice };
    assert(read_slice(b256::zero()).is_none());
    write_slice(b256::zero(), slice);
    let stored_slice = read_slice(b256::zero()).unwrap();
    assert_eq(slice, stored_slice);
}