Struct cw_storage_plus::IndexedSnapshotMap[][src]

pub struct IndexedSnapshotMap<'a, K, T, I> {
    pub idx: I,
    // some fields omitted
}
Expand description

IndexedSnapshotMap works like a SnapshotMap but has a secondary index

Fields

idx: I

This is meant to be read directly to get the proper types, like: map.idx.owner.items(…)

Implementations

Examples:

use cw_storage_plus::{IndexedSnapshotMap, Strategy, UniqueIndex};

#[derive(PartialEq, Debug, Clone)]
struct Data {
    pub name: String,
    pub age: u32,
}

let indexes = UniqueIndex::new(|d: &Data| d.age, "data__age");

IndexedSnapshotMap::<&[u8], Data, UniqueIndex<u32, Data>>::new(
    "data",
    "checkpoints",
    "changelog",
    Strategy::EveryBlock,
    indexes,
);

save will serialize the model and store, returns an error on serialization issues. this must load the old value to update the indexes properly if you loaded the old value earlier in the same function, use replace to avoid needless db reads

replace writes data to key. old_data must be the current stored value (from a previous load) and is used to properly update the index. This is used by save, replace, and update and can be called directly if you want to optimize

Loads the data, perform the specified action, and store the result in the database. This is shorthand for some common sequences, which may be useful.

If the data exists, action(Some(value)) is called. Otherwise action(None) is called.

load will return an error if no data is set at the given key, or on parse error

may_load will parse the data stored at the key if present, returns Ok(None) if no data there. returns an error on issues parsing

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.

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.