pub trait View:
Sized
+ Send
+ Sync {
type Context: Context;
const NUM_INIT_KEYS: usize;
// Required methods
fn context(&self) -> Self::Context;
fn pre_load(context: &Self::Context) -> Result<Vec<Vec<u8>>, ViewError>;
fn post_load(
context: Self::Context,
values: &[Option<Vec<u8>>],
) -> Result<Self, ViewError>;
fn rollback(&mut self);
fn has_pending_changes(&self) -> impl Future<Output = bool> + Send + Sync;
fn clear(&mut self);
fn pre_save(&self, batch: &mut Batch) -> Result<bool, ViewError>;
fn post_save(&mut self);
// Provided methods
fn load(
context: Self::Context,
) -> impl Future<Output = Result<Self, ViewError>> + Send + Sync { ... }
fn new(context: Self::Context) -> Result<Self, ViewError> { ... }
}Expand description
A view gives exclusive access to read and write the data stored at an underlying address in storage.
Required Associated Constants§
Sourceconst NUM_INIT_KEYS: usize
const NUM_INIT_KEYS: usize
The number of keys used for the initialization
Required Associated Types§
Required Methods§
Sourcefn pre_load(context: &Self::Context) -> Result<Vec<Vec<u8>>, ViewError>
fn pre_load(context: &Self::Context) -> Result<Vec<Vec<u8>>, ViewError>
Creates the keys needed for loading the view
Sourcefn post_load(
context: Self::Context,
values: &[Option<Vec<u8>>],
) -> Result<Self, ViewError>
fn post_load( context: Self::Context, values: &[Option<Vec<u8>>], ) -> Result<Self, ViewError>
Loads a view from the values
Sourcefn rollback(&mut self)
fn rollback(&mut self)
Discards all pending changes. After that flush should have no effect to storage.
Sourcefn has_pending_changes(&self) -> impl Future<Output = bool> + Send + Sync
fn has_pending_changes(&self) -> impl Future<Output = bool> + Send + Sync
Returns true if flushing this view would result in changes to the persistent storage.
Sourcefn clear(&mut self)
fn clear(&mut self)
Clears the view. That can be seen as resetting to default. If the clear is followed by a flush then all the relevant data is removed on the storage.
Sourcefn pre_save(&self, batch: &mut Batch) -> Result<bool, ViewError>
fn pre_save(&self, batch: &mut Batch) -> Result<bool, ViewError>
Computes the batch of operations to persist changes to storage without modifying the view.
Crash-resistant storage implementations accumulate the desired changes in the batch variable.
The returned boolean indicates whether the operation removes the view or not.
Sourcefn post_save(&mut self)
fn post_save(&mut self)
Updates the view state after the batch has been executed in the database.
This should be called after pre_save and after the batch has been successfully written to storage.
This leaves the view in a clean state with no pending changes.
May panic if pre_save was not called right before on self.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.