pub trait View<C>: Sized {
const NUM_INIT_KEYS: usize;
// Required methods
fn context(&self) -> &C;
fn pre_load(context: &C) -> Result<Vec<Vec<u8>>, ViewError>;
fn post_load(
context: C,
values: &[Option<Vec<u8>>],
) -> Result<Self, ViewError>;
fn load<'async_trait>(
context: C,
) -> Pin<Box<dyn Future<Output = Result<Self, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait;
fn rollback(&mut self);
fn has_pending_changes<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn clear(&mut self);
fn flush(&mut self, batch: &mut Batch) -> Result<bool, ViewError>;
// Provided method
fn new(context: C) -> 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 Methods§
Sourcefn pre_load(context: &C) -> Result<Vec<Vec<u8>>, ViewError>
fn pre_load(context: &C) -> Result<Vec<Vec<u8>>, ViewError>
Creates the keys needed for loading the view
Sourcefn post_load(context: C, values: &[Option<Vec<u8>>]) -> Result<Self, ViewError>
fn post_load(context: C, values: &[Option<Vec<u8>>]) -> Result<Self, ViewError>
Loads a view from the values
Sourcefn load<'async_trait>(
context: C,
) -> Pin<Box<dyn Future<Output = Result<Self, ViewError>> + Send + 'async_trait>>where
Self: 'async_trait,
fn load<'async_trait>(
context: C,
) -> Pin<Box<dyn Future<Output = Result<Self, ViewError>> + Send + 'async_trait>>where
Self: 'async_trait,
Loads a view
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<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn has_pending_changes<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
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.