pub trait StorageKey {
// Required method
fn as_storage_bytes(&self) -> impl AsRef<[u8]>;
// Provided method
fn mapping_slot(&self, slot: U256) -> U256 { ... }
}Expand description
Trait for types that can be used as storage mapping keys.
Keys are hashed using keccak256 along with the mapping’s base slot to determine the final storage location. This trait provides the byte representation used in that hash.
Required Methods§
Sourcefn as_storage_bytes(&self) -> impl AsRef<[u8]>
fn as_storage_bytes(&self) -> impl AsRef<[u8]>
Returns a byte slice for this type.
Provided Methods§
Sourcefn mapping_slot(&self, slot: U256) -> U256
fn mapping_slot(&self, slot: U256) -> U256
Compute storage slot for a mapping with this key.
Left-pads the key to the nearest 32-byte multiple, concatenates with the slot, and hashes.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.