Struct cw_storage_plus::IndexedSnapshotMap
source · pub struct IndexedSnapshotMap<'a, K, T, I> {
pub idx: I,
/* private fields */
}
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§
source§impl<'a, K, T, I> IndexedSnapshotMap<'a, K, T, I>
impl<'a, K, T, I> IndexedSnapshotMap<'a, K, T, I>
sourcepub fn new(
pk_namespace: &'a str,
checkpoints: &'a str,
changelog: &'a str,
strategy: Strategy,
indexes: I
) -> Self
pub fn new( pk_namespace: &'a str, checkpoints: &'a str, changelog: &'a str, strategy: Strategy, indexes: I ) -> Self
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,
);
pub fn changelog(&self) -> &Map<'a, (K, u64), ChangeSet<T>>
source§impl<'a, K, T, I> IndexedSnapshotMap<'a, K, T, I>where
T: Serialize + DeserializeOwned + Clone,
K: PrimaryKey<'a> + Prefixer<'a> + KeyDeserialize,
I: IndexList<T>,
impl<'a, K, T, I> IndexedSnapshotMap<'a, K, T, I>where T: Serialize + DeserializeOwned + Clone, K: PrimaryKey<'a> + Prefixer<'a> + KeyDeserialize, I: IndexList<T>,
pub fn add_checkpoint( &self, store: &mut dyn Storage, height: u64 ) -> StdResult<()>
pub fn remove_checkpoint( &self, store: &mut dyn Storage, height: u64 ) -> StdResult<()>
pub fn may_load_at_height( &self, store: &dyn Storage, k: K, height: u64 ) -> StdResult<Option<T>>
pub fn assert_checkpointed( &self, store: &dyn Storage, height: u64 ) -> StdResult<()>
pub fn key(&self, k: K) -> Path<T>
source§impl<'a, K, T, I> IndexedSnapshotMap<'a, K, T, I>where
K: PrimaryKey<'a> + Prefixer<'a> + KeyDeserialize,
T: Serialize + DeserializeOwned + Clone,
I: IndexList<T>,
impl<'a, K, T, I> IndexedSnapshotMap<'a, K, T, I>where K: PrimaryKey<'a> + Prefixer<'a> + KeyDeserialize, T: Serialize + DeserializeOwned + Clone, I: IndexList<T>,
sourcepub fn save(
&self,
store: &mut dyn Storage,
key: K,
data: &T,
height: u64
) -> StdResult<()>
pub fn save( &self, store: &mut dyn Storage, key: K, data: &T, height: u64 ) -> StdResult<()>
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
pub fn remove( &self, store: &mut dyn Storage, key: K, height: u64 ) -> StdResult<()>
sourcepub fn replace(
&self,
store: &mut dyn Storage,
key: K,
data: Option<&T>,
old_data: Option<&T>,
height: u64
) -> StdResult<()>
pub fn replace( &self, store: &mut dyn Storage, key: K, data: Option<&T>, old_data: Option<&T>, height: u64 ) -> StdResult<()>
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
sourcepub fn update<A, E>(
&self,
store: &mut dyn Storage,
key: K,
height: u64,
action: A
) -> Result<T, E>where
A: FnOnce(Option<T>) -> Result<T, E>,
E: From<StdError>,
pub fn update<A, E>( &self, store: &mut dyn Storage, key: K, height: u64, action: A ) -> Result<T, E>where A: FnOnce(Option<T>) -> Result<T, E>, E: From<StdError>,
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.
sourcepub fn load(&self, store: &dyn Storage, key: K) -> StdResult<T>
pub fn load(&self, store: &dyn Storage, key: K) -> StdResult<T>
load will return an error if no data is set at the given key, or on parse error
sourcepub fn may_load(&self, store: &dyn Storage, key: K) -> StdResult<Option<T>>
pub fn may_load(&self, store: &dyn Storage, key: K) -> StdResult<Option<T>>
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
pub fn no_prefix_raw(&self) -> Prefix<Vec<u8>, T, K>
source§impl<'a, K, T, I> IndexedSnapshotMap<'a, K, T, I>where
K: PrimaryKey<'a> + Prefixer<'a> + KeyDeserialize,
T: Serialize + DeserializeOwned + Clone,
I: IndexList<T>,
impl<'a, K, T, I> IndexedSnapshotMap<'a, K, T, I>where K: PrimaryKey<'a> + Prefixer<'a> + KeyDeserialize, T: Serialize + DeserializeOwned + Clone, I: IndexList<T>,
pub fn range_raw<'c>( &self, store: &'c dyn Storage, min: Option<Bound<'a, K>>, max: Option<Bound<'a, K>>, order: Order ) -> Box<dyn Iterator<Item = StdResult<Record<T>>> + 'c>where T: 'c,
pub fn keys_raw<'c>( &self, store: &'c dyn Storage, min: Option<Bound<'a, K>>, max: Option<Bound<'a, K>>, order: Order ) -> Box<dyn Iterator<Item = Vec<u8>> + 'c>
source§impl<'a, K, T, I> IndexedSnapshotMap<'a, K, T, I>where
T: Serialize + DeserializeOwned + Clone,
K: PrimaryKey<'a>,
I: IndexList<T>,
impl<'a, K, T, I> IndexedSnapshotMap<'a, K, T, I>where T: Serialize + DeserializeOwned + Clone, K: PrimaryKey<'a>, I: IndexList<T>,
pub fn sub_prefix( &self, p: K::SubPrefix ) -> Prefix<K::SuperSuffix, T, K::SuperSuffix>
pub fn prefix(&self, p: K::Prefix) -> Prefix<K::Suffix, T, K::Suffix>
source§impl<'a, K, T, I> IndexedSnapshotMap<'a, K, T, I>where
T: Serialize + DeserializeOwned + Clone,
K: PrimaryKey<'a> + KeyDeserialize,
I: IndexList<T>,
impl<'a, K, T, I> IndexedSnapshotMap<'a, K, T, I>where T: Serialize + DeserializeOwned + Clone, K: PrimaryKey<'a> + KeyDeserialize, I: IndexList<T>,
sourcepub fn prefix_range<'c>(
&self,
store: &'c dyn Storage,
min: Option<PrefixBound<'a, K::Prefix>>,
max: Option<PrefixBound<'a, K::Prefix>>,
order: Order
) -> Box<dyn Iterator<Item = StdResult<(K::Output, T)>> + 'c>where
T: 'c,
K: 'c,
K::Output: 'static,
'a: 'c,
pub fn prefix_range<'c>( &self, store: &'c dyn Storage, min: Option<PrefixBound<'a, K::Prefix>>, max: Option<PrefixBound<'a, K::Prefix>>, order: Order ) -> Box<dyn Iterator<Item = StdResult<(K::Output, T)>> + 'c>where T: 'c, K: 'c, K::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, K>>, max: Option<Bound<'a, K>>, order: Order ) -> Box<dyn Iterator<Item = StdResult<(K::Output, T)>> + 'c>where T: 'c, K::Output: 'static,
pub fn keys<'c>( &self, store: &'c dyn Storage, min: Option<Bound<'a, K>>, max: Option<Bound<'a, K>>, order: Order ) -> Box<dyn Iterator<Item = StdResult<K::Output>> + 'c>where T: 'c, K::Output: 'static,
Auto Trait Implementations§
impl<'a, K, T, I> RefUnwindSafe for IndexedSnapshotMap<'a, K, T, I>where I: RefUnwindSafe, K: RefUnwindSafe, T: RefUnwindSafe,
impl<'a, K, T, I> Send for IndexedSnapshotMap<'a, K, T, I>where I: Send, K: Send, T: Send,
impl<'a, K, T, I> Sync for IndexedSnapshotMap<'a, K, T, I>where I: Sync, K: Sync, T: Sync,
impl<'a, K, T, I> Unpin for IndexedSnapshotMap<'a, K, T, I>where I: Unpin, K: Unpin, T: Unpin,
impl<'a, K, T, I> UnwindSafe for IndexedSnapshotMap<'a, K, T, I>where I: UnwindSafe, K: UnwindSafe, T: UnwindSafe,
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere T: CastFrom<U>,
self
to type T
. The semantics of numeric casting with the as
operator are followed, so <T as As>::as_::<U>
can be used in the same way as T as U
for numeric conversions. Read more