pub struct UniqueIndex<'a, IK, T, PK = ()> { /* private fields */ }
Expand description

UniqueIndex stores (namespace, index_name, idx_value) -> {key, value} Allows one value per index (i.e. unique) and copies pk and data The optional PK type defines the type of Primary Key deserialization.

Implementations

Create a new UniqueIndex

idx_fn - lambda creating index key from index value idx_namespace - prefix for the index value

Example:
use cw_storage_plus::UniqueIndex;

struct Data {
    pub name: String,
    pub age: u32,
}

UniqueIndex::<_, _, ()>::new(|d: &Data| d.age, "data__age");

returns all items that match this secondary index, always by pk Ascending

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.