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>
impl<T: FadromaSerialize + FadromaDeserialize, N: Namespace, K: Key> ItemSpace<T, N, K>
pub const fn new() -> Self
pub fn save( &self, storage: &mut dyn Storage, key: impl Into<K>, item: &T ) -> StdResult<()>
pub fn load( &self, storage: &dyn Storage, key: impl Into<K> ) -> StdResult<Option<T>>
pub fn load_or_error( &self, storage: &dyn Storage, key: impl Into<K> ) -> StdResult<T>
pub fn remove(&self, storage: &mut dyn Storage, key: impl Into<K>)
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>
impl<T: FadromaSerialize + FadromaDeserialize + Humanize, N: Namespace, K: Key> ItemSpace<T, N, K>
source§impl<T: FadromaSerialize + FadromaDeserialize + Humanize, N: Namespace, K: Key> ItemSpace<T, N, K>where
<T as Humanize>::Output: Default,
impl<T: FadromaSerialize + FadromaDeserialize + Humanize, N: Namespace, K: Key> ItemSpace<T, N, K>where <T as Humanize>::Output: Default,
source§impl<T: FadromaSerialize + FadromaDeserialize + Default, N: Namespace, K: Key> ItemSpace<T, N, K>
impl<T: FadromaSerialize + FadromaDeserialize + Default, N: Namespace, K: Key> ItemSpace<T, N, K>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more