Struct cw_storage_plus::MultiIndex[][src]

pub struct MultiIndex<'a, IK, T, PK = ()> { /* 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 (optional) PK type defines the type of Primary Key deserialization.

Implementations

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(
    |d: &Data| d.age,
    "age",
    "age__owner",
);

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.

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.

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.