Struct cw_storage_plus::MultiIndex [−][src]
pub struct MultiIndex<'a, K, T> { /* fields omitted */ }
Expand description
MultiIndex stores (namespace, index_name, idx_value, pk) -> b“pk_len“. Allows many values per index, and references pk. The associated primary key value is stored in the main (pk_namespace) map, which stores (namespace, pk_namespace, pk) -> value.
The stored pk_len is used to recover the pk from the index namespace, and perform the secondary load of the associated value from the main map.
The MultiIndex definition must include a field for the pk. That is, the MultiIndex K value is always a n-tuple (n >= 2) and its last element must be the pk. The index function must therefore put the pk as last element, when generating the index.
Implementations
Create a new MultiIndex
idx_fn - lambda creating index key from value (first argument) and primary key (second argument) pk_namespace - prefix for the primary key idx_namespace - prefix for the index value
Example:
use cw_storage_plus::MultiIndex;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Clone)]
struct Data {
pub name: String,
pub age: u32,
}
MultiIndex::new(
|d: &Data, k: Vec<u8>| (d.age, k),
"age",
"age__owner",
);
impl<'a, K, T> MultiIndex<'a, K, T> where
T: Serialize + DeserializeOwned + Clone,
K: PrimaryKey<'a>,
impl<'a, K, T> MultiIndex<'a, K, T> where
T: Serialize + DeserializeOwned + Clone,
K: PrimaryKey<'a>,
impl<'a, K, T> MultiIndex<'a, K, T> where
T: Serialize + DeserializeOwned + Clone,
K: PrimaryKey<'a>,
impl<'a, K, T> MultiIndex<'a, K, T> where
T: Serialize + DeserializeOwned + Clone,
K: PrimaryKey<'a>,
pub fn range<'c>(
&'c self,
store: &'c dyn Storage,
min: Option<Bound>,
max: Option<Bound>,
order: Order
) -> Box<dyn Iterator<Item = StdResult<Record<T>>> + 'c> where
T: 'c,
pub fn keys<'c>(
&'c self,
store: &'c dyn Storage,
min: Option<Bound>,
max: Option<Bound>,
order: Order
) -> Box<dyn Iterator<Item = Vec<u8>> + 'c>
while range assumes you set the prefix to one element and call range over the last one,
prefix_range accepts bounds for the lowest and highest elements of the Prefix we wish to
accept, and iterates over those. There are some issues that distinguish these to and blindly
casting to Vec