Struct cw_storage_plus::SnapshotItem
source · pub struct SnapshotItem<'a, T> { /* private fields */ }
Expand description
Item that maintains a snapshot 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<'a, T> SnapshotItem<'a, T>
impl<'a, T> SnapshotItem<'a, T>
sourcepub const fn new(
storage_key: &'a str,
checkpoints: &'a str,
changelog: &'a str,
strategy: Strategy
) -> Self
pub const fn new(
storage_key: &'a str,
checkpoints: &'a str,
changelog: &'a str,
strategy: Strategy
) -> Self
Example:
use cw_storage_plus::{SnapshotItem, Strategy};
SnapshotItem::<'static, u64>::new(
"every",
"every__check",
"every__change",
Strategy::EveryBlock);
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 changelog(&self) -> Map<'_, u64, ChangeSet<T>>
source§impl<'a, T> SnapshotItem<'a, T>where
T: Serialize + DeserializeOwned + Clone,
impl<'a, T> SnapshotItem<'a, T>where
T: Serialize + DeserializeOwned + Clone,
pub fn save(&self, store: &mut dyn Storage, data: &T, height: u64) -> StdResult<()>
pub fn remove(&self, store: &mut dyn Storage, height: u64) -> StdResult<()>
sourcepub fn load(&self, store: &dyn Storage) -> StdResult<T>
pub fn load(&self, store: &dyn Storage) -> StdResult<T>
load will return an error if no data is set, or on parse error
sourcepub fn may_load(&self, store: &dyn Storage) -> StdResult<Option<T>>
pub fn may_load(&self, store: &dyn Storage) -> StdResult<Option<T>>
may_load will parse the data stored if present, returns Ok(None) if no data there. returns an error on parsing issues
pub fn may_load_at_height(
&self,
store: &dyn Storage,
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,
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,
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 a 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