referrerpolicy=no-referrer-when-downgrade
polkadot_sdk_frame::traits

Trait StoredMap

pub trait StoredMap<K, T>
where T: Default,
{ // Required methods fn get(k: &K) -> T; fn try_mutate_exists<R, E>( k: &K, f: impl FnOnce(&mut Option<T>) -> Result<R, E>, ) -> Result<R, E> where E: From<DispatchError>; // Provided methods fn mutate<R>(k: &K, f: impl FnOnce(&mut T) -> R) -> Result<R, DispatchError> { ... } fn mutate_exists<R>( k: &K, f: impl FnOnce(&mut Option<T>) -> R, ) -> Result<R, DispatchError> { ... } fn insert(k: &K, t: T) -> Result<(), DispatchError> { ... } fn remove(k: &K) -> Result<(), DispatchError> { ... } }
Expand description

An abstraction of a value stored within storage, but possibly as part of a larger composite item.

Required Methods§

fn get(k: &K) -> T

Get the item, or its default if it doesn’t yet exist; we make no distinction between the two.

fn try_mutate_exists<R, E>( k: &K, f: impl FnOnce(&mut Option<T>) -> Result<R, E>, ) -> Result<R, E>
where E: From<DispatchError>,

Maybe mutate the item only if an Ok value is returned from f. Do nothing if an Err is returned. It is removed or reset to default value if it has been mutated to None. f will always be called with an option representing if the storage item exists (Some<V>) or if the storage item does not exist (None), independent of the QueryType.

Provided Methods§

fn mutate<R>(k: &K, f: impl FnOnce(&mut T) -> R) -> Result<R, DispatchError>

Mutate the item.

fn mutate_exists<R>( k: &K, f: impl FnOnce(&mut Option<T>) -> R, ) -> Result<R, DispatchError>

Mutate the item, removing or resetting to default value if it has been mutated to None.

This is infallible as long as the value does not get destroyed.

fn insert(k: &K, t: T) -> Result<(), DispatchError>

Set the item to something new.

fn remove(k: &K) -> Result<(), DispatchError>

Remove the item or otherwise replace it with its default value; we don’t care which.

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.

Implementors§

§

impl<S, K, T> StoredMap<K, T> for StorageMapShim<S, K, T>
where S: StorageMap<K, T, Query = T>, K: FullCodec, T: FullCodec + Default,

§

impl<T> StoredMap<<T as Config>::AccountId, <T as Config>::AccountData> for Pallet<T>
where T: Config,

Implement StoredMap for a simple single-item, provide-when-not-default system. This works fine for storing a single item which allows the account to continue existing as long as it’s not empty/default.

Anything more complex will need more sophisticated logic.

impl<T: Config<I>, I: 'static> StoredMap<(<T as Config<I>>::AssetId, <T as Config>::AccountId), <T as Config<I>>::Extra> for Pallet<T, I>