pub struct MultiIndex<'a, IK, T, PK> { /* private fields */ }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 PK type defines the type of Primary Key, both for deserialization, and
more important, as the type-safe bound key type.
This type must match the encompassing IndexedMap primary key type,
or its owned variant.
Implementations§
Source§impl<'a, IK, T, PK> MultiIndex<'a, IK, T, PK>
impl<'a, IK, T, PK> MultiIndex<'a, IK, T, PK>
Sourcepub const fn new(
idx_fn: fn(&[u8], &T) -> IK,
pk_namespace: &'a str,
idx_namespace: &'static str,
) -> Self
pub const fn new( idx_fn: fn(&[u8], &T) -> IK, pk_namespace: &'a str, idx_namespace: &'static str, ) -> Self
Create a new MultiIndex
idx_fn - lambda creating index key from value 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,
}
let index: MultiIndex<_, _, String> = MultiIndex::new(
|_pk: &[u8], d: &Data| d.age,
"age",
"age__owner",
);Source§impl<'a, IK, T, PK> MultiIndex<'a, IK, T, PK>where
PK: PrimaryKey<'a> + KeyDeserialize,
T: Serialize + DeserializeOwned + Clone,
IK: PrimaryKey<'a> + Prefixer<'a>,
impl<'a, IK, T, PK> MultiIndex<'a, IK, T, PK>where
PK: PrimaryKey<'a> + KeyDeserialize,
T: Serialize + DeserializeOwned + Clone,
IK: PrimaryKey<'a> + Prefixer<'a>,
Source§impl<'a, IK, T, PK> MultiIndex<'a, IK, T, PK>where
T: Serialize + DeserializeOwned + Clone,
IK: PrimaryKey<'a> + Prefixer<'a> + KeyDeserialize,
PK: PrimaryKey<'a> + KeyDeserialize,
impl<'a, IK, T, PK> MultiIndex<'a, IK, T, PK>where
T: Serialize + DeserializeOwned + Clone,
IK: PrimaryKey<'a> + Prefixer<'a> + KeyDeserialize,
PK: PrimaryKey<'a> + KeyDeserialize,
pub fn range_raw<'c>(
&'c self,
store: &'c dyn Storage,
min: Option<Bound<'a, (IK, PK)>>,
max: Option<Bound<'a, (IK, PK)>>,
order: Order,
) -> Box<dyn Iterator<Item = StdResult<Record<T>>> + 'c>where
T: 'c,
pub fn keys_raw<'c>( &'c self, store: &'c dyn Storage, min: Option<Bound<'a, (IK, PK)>>, max: Option<Bound<'a, (IK, PK)>>, order: Order, ) -> Box<dyn Iterator<Item = Vec<u8>> + 'c>
Sourcepub fn prefix_range_raw<'c>(
&'c self,
store: &'c dyn Storage,
min: Option<PrefixBound<'a, IK>>,
max: Option<PrefixBound<'a, IK>>,
order: Order,
) -> Box<dyn Iterator<Item = StdResult<Record<T>>> + 'c>where
T: 'c,
'a: 'c,
pub fn prefix_range_raw<'c>(
&'c self,
store: &'c dyn Storage,
min: Option<PrefixBound<'a, IK>>,
max: Option<PrefixBound<'a, IK>>,
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, IK, T, PK> MultiIndex<'a, IK, T, PK>where
PK: PrimaryKey<'a> + KeyDeserialize,
T: Serialize + DeserializeOwned + Clone,
IK: PrimaryKey<'a> + Prefixer<'a>,
impl<'a, IK, T, PK> MultiIndex<'a, IK, T, PK>where
PK: PrimaryKey<'a> + KeyDeserialize,
T: Serialize + DeserializeOwned + Clone,
IK: PrimaryKey<'a> + Prefixer<'a>,
pub fn prefix(&self, p: IK) -> IndexPrefix<PK, T, PK>
pub fn sub_prefix(&self, p: IK::Prefix) -> IndexPrefix<PK, T, (IK::Suffix, PK)>
Source§impl<'a, IK, T, PK> MultiIndex<'a, IK, T, PK>where
PK: PrimaryKey<'a> + KeyDeserialize,
T: Serialize + DeserializeOwned + Clone,
IK: PrimaryKey<'a> + KeyDeserialize + Prefixer<'a>,
impl<'a, IK, T, PK> MultiIndex<'a, IK, T, PK>where
PK: PrimaryKey<'a> + KeyDeserialize,
T: Serialize + DeserializeOwned + Clone,
IK: PrimaryKey<'a> + KeyDeserialize + Prefixer<'a>,
Sourcepub fn prefix_range<'c>(
&self,
store: &'c dyn Storage,
min: Option<PrefixBound<'a, IK>>,
max: Option<PrefixBound<'a, IK>>,
order: Order,
) -> Box<dyn Iterator<Item = StdResult<(PK::Output, T)>> + 'c>where
T: 'c,
IK: 'c,
PK: 'c,
PK::Output: 'static,
'a: 'c,
pub fn prefix_range<'c>(
&self,
store: &'c dyn Storage,
min: Option<PrefixBound<'a, IK>>,
max: Option<PrefixBound<'a, IK>>,
order: Order,
) -> Box<dyn Iterator<Item = StdResult<(PK::Output, T)>> + 'c>where
T: 'c,
IK: 'c,
PK: 'c,
PK::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<'c>(
&self,
store: &'c dyn Storage,
min: Option<Bound<'a, (IK, PK)>>,
max: Option<Bound<'a, (IK, PK)>>,
order: Order,
) -> Box<dyn Iterator<Item = StdResult<(PK::Output, T)>> + 'c>where
T: 'c,
PK::Output: 'static,
pub fn keys<'c>(
&self,
store: &'c dyn Storage,
min: Option<Bound<'a, (IK, PK)>>,
max: Option<Bound<'a, (IK, PK)>>,
order: Order,
) -> Box<dyn Iterator<Item = StdResult<PK::Output>> + 'c>where
T: 'c,
PK::Output: 'static,
Trait Implementations§
Source§impl<'a, IK, T, PK> Index<T> for MultiIndex<'a, IK, T, PK>
impl<'a, IK, T, PK> Index<T> for MultiIndex<'a, IK, T, PK>
Auto Trait Implementations§
impl<'a, IK, T, PK> Freeze for MultiIndex<'a, IK, T, PK>
impl<'a, IK, T, PK> RefUnwindSafe for MultiIndex<'a, IK, T, PK>where
PK: RefUnwindSafe,
impl<'a, IK, T, PK> Send for MultiIndex<'a, IK, T, PK>where
PK: Send,
impl<'a, IK, T, PK> Sync for MultiIndex<'a, IK, T, PK>where
PK: Sync,
impl<'a, IK, T, PK> Unpin for MultiIndex<'a, IK, T, PK>where
PK: Unpin,
impl<'a, IK, T, PK> UnwindSafe for MultiIndex<'a, IK, T, PK>where
PK: 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
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