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
Auto Trait Implementations§
impl<'a, T> RefUnwindSafe for SnapshotItem<'a, T>where T: RefUnwindSafe,
impl<'a, T> Send for SnapshotItem<'a, T>where T: Send,
impl<'a, T> Sync for SnapshotItem<'a, T>where T: Sync,
impl<'a, T> Unpin for SnapshotItem<'a, T>where T: Unpin,
impl<'a, T> UnwindSafe for SnapshotItem<'a, T>where 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>,
Casts
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 moresource§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
Mutably borrows from an owned value. Read more