pub struct SnapshotMap<K, T> { /* private fields */ }Expand description
Map that maintains a snapshots of one or more checkpoints. We can query historical data as well as current state. What data is snapshotted depends on the Strategy.
Implementations§
Source§impl<K, T> SnapshotMap<K, T>
impl<K, T> SnapshotMap<K, T>
Sourcepub const fn new(
pk: &'static str,
checkpoints: &'static str,
changelog: &'static str,
strategy: Strategy,
) -> Self
pub const fn new( pk: &'static str, checkpoints: &'static str, changelog: &'static str, strategy: Strategy, ) -> Self
Creates a new SnapshotMap with the given storage keys and strategy.
This is a const fn only suitable when all the storage keys provided are
static strings.
Example:
use cw_storage_plus::{SnapshotMap, Strategy};
SnapshotMap::<&[u8], &str>::new(
"never",
"never__check",
"never__change",
Strategy::EveryBlock
);Sourcepub fn new_dyn(
pk: impl Into<Namespace>,
checkpoints: impl Into<Namespace>,
changelog: impl Into<Namespace>,
strategy: Strategy,
) -> Self
pub fn new_dyn( pk: impl Into<Namespace>, checkpoints: impl Into<Namespace>, changelog: impl Into<Namespace>, strategy: Strategy, ) -> Self
Creates a new SnapshotMap with the given storage keys and strategy.
Use this if you might need to handle dynamic strings. Otherwise, you might
prefer SnapshotMap::new.
Example:
use cw_storage_plus::{SnapshotMap, Strategy};
let key = "every";
let checkpoints_key = format!("{}_check", key);
let changelog_key = format!("{}_change", key);
SnapshotMap::<&[u8], &str>::new_dyn(
key,
checkpoints_key,
changelog_key,
Strategy::EveryBlock);pub fn changelog(&self) -> &Map<(K, u64), ChangeSet<T>>
Source§impl<'a, K, T> SnapshotMap<K, T>
impl<'a, K, T> SnapshotMap<K, T>
Source§impl<'a, K, T> SnapshotMap<K, T>
impl<'a, K, T> SnapshotMap<K, T>
pub fn key(&self, k: K) -> Path<T>
pub fn save( &self, store: &mut dyn Storage, k: K, data: &T, height: u64, ) -> StdResult<()>
pub fn remove( &self, store: &mut dyn Storage, k: K, height: u64, ) -> StdResult<()>
Sourcepub fn load(&self, store: &dyn Storage, k: K) -> StdResult<T>
pub fn load(&self, store: &dyn Storage, k: 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, k: K) -> StdResult<Option<T>>
pub fn may_load(&self, store: &dyn Storage, k: 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 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<()>
Sourcepub fn update<A, E>(
&self,
store: &mut dyn Storage,
k: K,
height: u64,
action: A,
) -> Result<T, E>
pub fn update<A, E>( &self, store: &mut dyn Storage, k: K, height: u64, action: A, ) -> Result<T, E>
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.
This is a bit more customized than needed to only read “old” value 1 time, not 2 per naive approach
Source§impl<'a, K, T> SnapshotMap<K, T>
impl<'a, K, T> SnapshotMap<K, 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>where
T: 'c,
Source§impl<'a, K, T> SnapshotMap<K, T>
impl<'a, K, T> SnapshotMap<K, 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,
pub fn prefix(&self, p: K::Prefix) -> Prefix<K::Suffix, T, K::Suffix>
pub fn sub_prefix( &self, p: K::SubPrefix, ) -> Prefix<K::SuperSuffix, T, K::SuperSuffix>
Auto Trait Implementations§
impl<K, T> Freeze for SnapshotMap<K, T>
impl<K, T> RefUnwindSafe for SnapshotMap<K, T>where
K: RefUnwindSafe,
T: RefUnwindSafe,
impl<K, T> Send for SnapshotMap<K, T>
impl<K, T> Sync for SnapshotMap<K, T>
impl<K, T> Unpin for SnapshotMap<K, T>
impl<K, T> UnwindSafe for SnapshotMap<K, T>where
K: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more