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",
);

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 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.