pub struct IndexedMap<K, T, I> {
pub idx: I,
/* private fields */
}Expand description
IndexedMap works like a Map but has a secondary index
Fields§
§idx: IThis is meant to be read directly to get the proper types, like: map.idx.owner.items(…)
Implementations§
Source§impl<'a, K, T, I> IndexedMap<K, T, I>
impl<'a, K, T, I> IndexedMap<K, T, I>
Sourcepub const fn new(pk_namespace: &'static str, indexes: I) -> Self
pub const fn new(pk_namespace: &'static str, indexes: I) -> Self
Creates a new IndexedMap with the given storage key. This is a constant function only suitable
when you have a prefix in the form of a static string slice.
Sourcepub fn new_dyn(pk_namespace: impl Into<Namespace>, indexes: I) -> Self
pub fn new_dyn(pk_namespace: impl Into<Namespace>, indexes: I) -> Self
Creates a new IndexedMap with the given storage key. Use this if you might need to handle
a dynamic string. Otherwise, you should probably prefer IndexedMap::new.
pub fn key(&self, k: K) -> Path<T>
Source§impl<'a, K, T, I> IndexedMap<K, T, I>
impl<'a, K, T, I> IndexedMap<K, T, I>
Sourcepub fn save(&self, store: &mut dyn Storage, key: K, data: &T) -> StdResult<()>
pub fn save(&self, store: &mut dyn Storage, key: K, data: &T) -> StdResult<()>
save will serialize the model and store, returns an error on serialization issues. this must load the old value to update the indexes properly if you loaded the old value earlier in the same function, use replace to avoid needless db reads
pub fn remove(&self, store: &mut dyn Storage, key: K) -> StdResult<()>
Sourcepub fn replace(
&self,
store: &mut dyn Storage,
key: K,
data: Option<&T>,
old_data: Option<&T>,
) -> StdResult<()>
pub fn replace( &self, store: &mut dyn Storage, key: K, data: Option<&T>, old_data: Option<&T>, ) -> StdResult<()>
replace writes data to key. old_data must be the current stored value (from a previous load) and is used to properly update the index. This is used by save, replace, and update and can be called directly if you want to optimize
Sourcepub fn update<A, E>(
&self,
store: &mut dyn Storage,
key: K,
action: A,
) -> Result<T, E>
pub fn update<A, E>( &self, store: &mut dyn Storage, key: K, action: A, ) -> Result<T, E>
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 load(&self, store: &dyn Storage, key: K) -> StdResult<T>
pub fn load(&self, store: &dyn Storage, key: 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, key: K) -> StdResult<Option<T>>
pub fn may_load(&self, store: &dyn Storage, key: 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
Source§impl<'a, K, T, I> IndexedMap<K, T, I>
impl<'a, K, T, I> IndexedMap<K, T, I>
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, I> IndexedMap<K, T, I>
impl<'a, K, T, I> IndexedMap<K, T, I>
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, I> IndexedMap<K, T, I>
impl<'a, K, T, I> IndexedMap<K, T, I>
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.
pub fn range_raw<'c>(
&self,
store: &'c dyn Storage,
min: Option<Bound<'a, K>>,
max: Option<Bound<'a, K>>,
order: Order,
) -> Box<dyn Iterator<Item = StdResult<Record<T>>> + 'c>where
T: 'c,
pub fn keys_raw<'c>( &self, store: &'c dyn Storage, min: Option<Bound<'a, K>>, max: Option<Bound<'a, K>>, order: Order, ) -> Box<dyn Iterator<Item = Vec<u8>> + 'c>
pub fn range<'c>(
&self,
store: &'c dyn Storage,
min: Option<Bound<'a, K>>,
max: Option<Bound<'a, K>>,
order: Order,
) -> Box<dyn Iterator<Item = StdResult<(K::Output, T)>> + 'c>where
T: 'c,
K::Output: 'static,
pub fn keys<'c>(
&self,
store: &'c dyn Storage,
min: Option<Bound<'a, K>>,
max: Option<Bound<'a, K>>,
order: Order,
) -> Box<dyn Iterator<Item = StdResult<K::Output>> + 'c>where
T: 'c,
K::Output: 'static,
Auto Trait Implementations§
impl<K, T, I> Freeze for IndexedMap<K, T, I>where
I: Freeze,
impl<K, T, I> RefUnwindSafe for IndexedMap<K, T, I>
impl<K, T, I> Send for IndexedMap<K, T, I>
impl<K, T, I> Sync for IndexedMap<K, T, I>
impl<K, T, I> Unpin for IndexedMap<K, T, I>
impl<K, T, I> UnwindSafe for IndexedMap<K, T, I>
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more