Struct cw_storage_plus::Map
source · pub struct Map<'a, K, T> { /* private fields */ }
Implementations§
source§impl<'a, K, T> Map<'a, K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a>,
impl<'a, K, T> Map<'a, K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a>,
pub fn key(&self, k: K) -> Path<T>
pub fn save(&self, store: &mut dyn Storage, k: K, data: &T) -> StdResult<()>
pub fn remove(&self, store: &mut dyn Storage, k: K)
sourcepub fn load(&self, store: &dyn Storage, k: K) -> StdResult<T>
pub fn load(&self, store: &dyn Storage, k: K) -> StdResult<T>
load will return an error if no data is set at the given key, or on parse error
sourcepub fn may_load(&self, store: &dyn Storage, k: K) -> StdResult<Option<T>>
pub fn may_load(&self, store: &dyn Storage, k: K) -> StdResult<Option<T>>
may_load will parse the data stored at the key if present, returns Ok(None) if no data there. returns an error on issues parsing
sourcepub fn has(&self, store: &dyn Storage, k: K) -> bool
pub fn has(&self, store: &dyn Storage, k: K) -> bool
has returns true or false if any data is at this key, without parsing or interpreting the contents.
sourcepub fn update<A, E>(
&self,
store: &mut dyn Storage,
k: K,
action: A
) -> Result<T, E>where
A: FnOnce(Option<T>) -> Result<T, E>,
E: From<StdError>,
pub fn update<A, E>(
&self,
store: &mut dyn Storage,
k: K,
action: A
) -> Result<T, E>where
A: FnOnce(Option<T>) -> Result<T, E>,
E: From<StdError>,
Loads the data, perform the specified action, and store the result in the database. This is shorthand for some common sequences, which may be useful.
If the data exists, action(Some(value))
is called. Otherwise action(None)
is called.
sourcepub fn query<Q: CustomQuery>(
&self,
querier: &QuerierWrapper<'_, Q>,
remote_contract: Addr,
k: K
) -> StdResult<Option<T>>
pub fn query<Q: CustomQuery>(
&self,
querier: &QuerierWrapper<'_, Q>,
remote_contract: Addr,
k: K
) -> StdResult<Option<T>>
If you import the proper Map from the remote contract, this will let you read the data from a remote contract in a type-safe way using WasmQuery::RawQuery
source§impl<'a, K, T> Map<'a, K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a>,
impl<'a, K, T> Map<'a, K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a>,
pub fn sub_prefix(
&self,
p: K::SubPrefix
) -> Prefix<K::SuperSuffix, T, K::SuperSuffix>
pub fn prefix(&self, p: K::Prefix) -> Prefix<K::Suffix, T, K::Suffix>
source§impl<'a, K, T> Map<'a, K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a>,
impl<'a, K, T> Map<'a, K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a>,
sourcepub fn prefix_range_raw<'c>(
&self,
store: &'c dyn Storage,
min: Option<PrefixBound<'a, K::Prefix>>,
max: Option<PrefixBound<'a, K::Prefix>>,
order: Order
) -> Box<dyn Iterator<Item = StdResult<Record<T>>> + 'c>where
T: 'c,
'a: 'c,
pub fn prefix_range_raw<'c>(
&self,
store: &'c dyn Storage,
min: Option<PrefixBound<'a, K::Prefix>>,
max: Option<PrefixBound<'a, K::Prefix>>,
order: Order
) -> Box<dyn Iterator<Item = StdResult<Record<T>>> + 'c>where
T: 'c,
'a: 'c,
While range_raw
over a prefix
fixes the prefix to one element and iterates over the
remaining, prefix_range_raw
accepts bounds for the lowest and highest elements of the Prefix
itself, and iterates over those (inclusively or exclusively, depending on PrefixBound
).
There are some issues that distinguish these two, and blindly casting to Vec<u8>
doesn’t
solve them.
source§impl<'a, K, T> Map<'a, K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a> + KeyDeserialize,
impl<'a, K, T> Map<'a, K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a> + KeyDeserialize,
sourcepub fn prefix_range<'c>(
&self,
store: &'c dyn Storage,
min: Option<PrefixBound<'a, K::Prefix>>,
max: Option<PrefixBound<'a, K::Prefix>>,
order: Order
) -> Box<dyn Iterator<Item = StdResult<(K::Output, T)>> + 'c>where
T: 'c,
K: 'c,
K::Output: 'static,
'a: 'c,
pub fn prefix_range<'c>(
&self,
store: &'c dyn Storage,
min: Option<PrefixBound<'a, K::Prefix>>,
max: Option<PrefixBound<'a, K::Prefix>>,
order: Order
) -> Box<dyn Iterator<Item = StdResult<(K::Output, T)>> + 'c>where
T: 'c,
K: 'c,
K::Output: 'static,
'a: 'c,
While range
over a prefix
fixes the prefix to one element and iterates over the
remaining, prefix_range
accepts bounds for the lowest and highest elements of the
Prefix
itself, and iterates over those (inclusively or exclusively, depending on
PrefixBound
).
There are some issues that distinguish these two, and blindly casting to Vec<u8>
doesn’t
solve them.