Struct fadroma::storage::ItemSpace

source ·
pub struct ItemSpace<T: FadromaSerialize + FadromaDeserialize, N: Namespace, K: Key> { /* private fields */ }
Expand description

Storage type that stores many items under the given Namespace. The key can be anything that implements Key and the most suitable type of key should be chosen depending on the scenario.

Examples

use fadroma::{
    cosmwasm_std::{
        CanonicalAddr, Api,
        testing::mock_dependencies
    },
    storage::{ItemSpace, TypedKey2}
};
 
fadroma::namespace!(NumbersNs, b"numbers");
const NUMBERS: ItemSpace::<u64, NumbersNs, TypedKey2<CanonicalAddr, u8>> = ItemSpace::new();
 
let mut deps = mock_dependencies();
 
let address = deps.api.addr_canonicalize("user").unwrap();
let index = 1u8;
 
let storage = deps.as_mut().storage;
 
NUMBERS.save(storage, (&address, &index), &100).unwrap();
 
let stored = NUMBERS.load_or_default(storage, (&address, &index)).unwrap();
assert_eq!(stored, 100);
 
let index = 2u8;
let stored = NUMBERS.load(storage, (&address, &index)).unwrap();
assert!(stored.is_none());
 

Implementations§

source§

impl<T: FadromaSerialize + FadromaDeserialize, N: Namespace, K: Key> ItemSpace<T, N, K>

source

pub const fn new() -> Self

source

pub fn save( &self, storage: &mut dyn Storage, key: impl Into<K>, item: &T ) -> StdResult<()>

source

pub fn load( &self, storage: &dyn Storage, key: impl Into<K> ) -> StdResult<Option<T>>

source

pub fn load_or_error( &self, storage: &dyn Storage, key: impl Into<K> ) -> StdResult<T>

source

pub fn remove(&self, storage: &mut dyn Storage, key: impl Into<K>)

source

pub fn canonize_and_save<Input: Canonize<Output = T>>( &self, deps: DepsMut<'_>, key: impl Into<K>, item: Input ) -> StdResult<()>

source§

impl<T: FadromaSerialize + FadromaDeserialize + Humanize, N: Namespace, K: Key> ItemSpace<T, N, K>

source

pub fn load_humanize( &self, deps: Deps<'_>, key: impl Into<K> ) -> StdResult<Option<<T as Humanize>::Output>>

source

pub fn load_humanize_or_error( &self, deps: Deps<'_>, key: impl Into<K> ) -> StdResult<<T as Humanize>::Output>

source§

impl<T: FadromaSerialize + FadromaDeserialize + Humanize, N: Namespace, K: Key> ItemSpace<T, N, K>where <T as Humanize>::Output: Default,

source

pub fn load_humanize_or_default( &self, deps: Deps<'_>, key: impl Into<K> ) -> StdResult<<T as Humanize>::Output>

source§

impl<T: FadromaSerialize + FadromaDeserialize + Default, N: Namespace, K: Key> ItemSpace<T, N, K>

source

pub fn load_or_default( &self, storage: &dyn Storage, key: impl Into<K> ) -> StdResult<T>

Auto Trait Implementations§

§

impl<T, N, K> RefUnwindSafe for ItemSpace<T, N, K>where K: RefUnwindSafe, N: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, N, K> Send for ItemSpace<T, N, K>where K: Send, N: Send, T: Send,

§

impl<T, N, K> Sync for ItemSpace<T, N, K>where K: Sync, N: Sync, T: Sync,

§

impl<T, N, K> Unpin for ItemSpace<T, N, K>where K: Unpin, N: Unpin, T: Unpin,

§

impl<T, N, K> UnwindSafe for ItemSpace<T, N, K>where K: UnwindSafe, N: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V