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 flush(&mut self, batch: &mut Batch) -> Result<bool, ViewError>;
// 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 flush(&mut self, batch: &mut Batch) -> Result<bool, ViewError>
fn flush(&mut self, batch: &mut Batch) -> Result<bool, ViewError>
Persists changes to storage. This leaves the view still usable and is essentially neutral to the
program running. Crash-resistant storage implementations are expected to accumulate the desired
changes in the batch variable first. If the view is dropped without calling flush, staged
changes are simply lost.
The returned boolean indicates whether the operation removes the view or not.
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.