pub fn clear<T>(slot: b256, offset: u64) -> bool 
Expand description

Clears a value of type T from slots of 32 bytes each, starting at slot with an offset given in words.

Deprecation Notice

This function is deprecated in favor of clear_quads, clear_slots, and clear_slots_existed.
To preserve exactly the same behavior as clear, use clear_quads.
To clear values contained in dynamic slots of variable sizes, use clear_slots.
To clear values contained in dynamic slots of variable sizes, and obtain information
about whether all the cleared slots were previously set, use clear_slots_existed.

Additional Information

The function returns true if all the cleared storage slots were previously set, otherwise, false.
If the information about whether the cleared storage slots were previously set is not needed,
consider using clear_slots because it is more gas efficient.

If T is a zero-sized type, no storage access will occur. Storage API does not store zero-sized types in storage,
so clearing a zero-sized type from the slot and offset will have no effect.

If T is a zero-sized type, the function always returns true, regardless of the slot and offset.

Arguments

  • slot: [b256] - The storage slot from which to count the offset. This or the following slots can be cleared.
  • offset: [u64] - An offset, in words, from the start of slot, from which the value should be cleared.

Returns

  • [bool] - true if all the cleared storage slots were previously set. Otherwise, false.

Number of Storage Accesses

  • Clears: 1

Examples

use std::storage::storage_api::{read, write, clear};

fn foo() {
    let five = 5_u64;
    write(b256::zero(), 0, five);
    let cleared = clear::<u64>(b256::zero(), 0);
    assert(cleared);
    assert(read::<u64>(b256::zero(), 0).is_none());
}