Skip to main content

clear_elements

Function clear_elements 

Source
fn clear_elements<T: Storable, S: StorageOps>(
    storage: &mut S,
    data_start: U256,
    from: usize,
    to: usize,
) -> Result<()>
Expand description

Clears storage occupied exclusively by Vec elements in the index range [from, to).

Packed elements (T::BYTES <= 16) share storage words, so this only zeroes whole packed slots that contain no element before from:

  • from = 0 clears from slot 0. This is the delete path and clears every slot that may contain any element in [0, to); e.g. for 16-byte elements, [0, 1) clears slot 0.
  • from > 0 starts at calc_packed_slot_count(from, T::BYTES), intentionally preserving the boundary slot that may also contain live elements < from; e.g. for 16-byte elements, [1, 2) clears nothing because elements 0 and 1 share slot 0. Shrink callers rely on the subsequent packed-slot rewrite to clear stale lanes in that boundary slot.

Unpacked elements delegate to T::delete per element so nested dynamic storables are recursively cleared.