Trait linera_sdk::views::View

source ·
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§

source

const NUM_INIT_KEYS: usize

The number of keys used for the initialization

Required Methods§

source

fn context(&self) -> &C

Obtains a mutable reference to the internal context.

source

fn pre_load(context: &C) -> Result<Vec<Vec<u8>>, ViewError>

Creates the keys needed for loading the view

source

fn post_load(context: C, values: &[Option<Vec<u8>>]) -> Result<Self, ViewError>

Loads a view from the values

source

fn load<'async_trait>( context: C, ) -> Pin<Box<dyn Future<Output = Result<Self, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait,

Loads a view

source

fn rollback(&mut self)

Discards all pending changes. After that flush should have no effect to storage.

source

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.

source

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.

source

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§

source

fn new(context: C) -> Result<Self, ViewError>

Builds a trivial view that is already deleted

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<C> View<C> for ChainStateView<C>
where C: Clone + Context + Send + Sync + 'static,

source§

const NUM_INIT_KEYS: usize = 46usize

source§

fn context(&self) -> &C

source§

fn pre_load(context: &C) -> Result<Vec<Vec<u8>>, ViewError>

source§

fn post_load( context: C, values: &[Option<Vec<u8>>], ) -> Result<ChainStateView<C>, ViewError>

source§

fn load<'async_trait>( context: C, ) -> Pin<Box<dyn Future<Output = Result<ChainStateView<C>, ViewError>> + Send + 'async_trait>>
where ChainStateView<C>: 'async_trait,

source§

fn rollback(&mut self)

source§

fn has_pending_changes<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where 'life0: 'async_trait, ChainStateView<C>: 'async_trait,

source§

fn flush(&mut self, batch: &mut Batch) -> Result<bool, ViewError>

source§

fn clear(&mut self)

source§

impl<C> View<C> for ChainManager<C>
where C: Clone + Context + Send + Sync + 'static,

source§

const NUM_INIT_KEYS: usize = 14usize

source§

fn context(&self) -> &C

source§

fn pre_load(context: &C) -> Result<Vec<Vec<u8>>, ViewError>

source§

fn post_load( context: C, values: &[Option<Vec<u8>>], ) -> Result<ChainManager<C>, ViewError>

source§

fn load<'async_trait>( context: C, ) -> Pin<Box<dyn Future<Output = Result<ChainManager<C>, ViewError>> + Send + 'async_trait>>
where ChainManager<C>: 'async_trait,

source§

fn rollback(&mut self)

source§

fn has_pending_changes<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where 'life0: 'async_trait, ChainManager<C>: 'async_trait,

source§

fn flush(&mut self, batch: &mut Batch) -> Result<bool, ViewError>

source§

fn clear(&mut self)

source§

impl<C> View<C> for ApplicationRegistryView<C>
where C: Context + Send + Sync + Clone + 'static,

source§

const NUM_INIT_KEYS: usize = 1usize

source§

fn context(&self) -> &C

source§

fn pre_load(context: &C) -> Result<Vec<Vec<u8>>, ViewError>

source§

fn post_load( context: C, values: &[Option<Vec<u8>>], ) -> Result<ApplicationRegistryView<C>, ViewError>

source§

fn load<'async_trait>( context: C, ) -> Pin<Box<dyn Future<Output = Result<ApplicationRegistryView<C>, ViewError>> + Send + 'async_trait>>
where ApplicationRegistryView<C>: 'async_trait,

source§

fn rollback(&mut self)

source§

fn has_pending_changes<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where 'life0: 'async_trait, ApplicationRegistryView<C>: 'async_trait,

source§

fn flush(&mut self, batch: &mut Batch) -> Result<bool, ViewError>

source§

fn clear(&mut self)

source§

impl<C> View<C> for ExecutionStateView<C>
where C: Context + Send + Sync + Clone + 'static,

source§

const NUM_INIT_KEYS: usize = 23usize

source§

fn context(&self) -> &C

source§

fn pre_load(context: &C) -> Result<Vec<Vec<u8>>, ViewError>

source§

fn post_load( context: C, values: &[Option<Vec<u8>>], ) -> Result<ExecutionStateView<C>, ViewError>

source§

fn load<'async_trait>( context: C, ) -> Pin<Box<dyn Future<Output = Result<ExecutionStateView<C>, ViewError>> + Send + 'async_trait>>
where ExecutionStateView<C>: 'async_trait,

source§

fn rollback(&mut self)

source§

fn has_pending_changes<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where 'life0: 'async_trait, ExecutionStateView<C>: 'async_trait,

source§

fn flush(&mut self, batch: &mut Batch) -> Result<bool, ViewError>

source§

fn clear(&mut self)

source§

impl<C> View<C> for SystemExecutionStateView<C>
where C: Context + Send + Sync + Clone + 'static,

source§

const NUM_INIT_KEYS: usize = 22usize

source§

fn context(&self) -> &C

source§

fn pre_load(context: &C) -> Result<Vec<Vec<u8>>, ViewError>

source§

fn post_load( context: C, values: &[Option<Vec<u8>>], ) -> Result<SystemExecutionStateView<C>, ViewError>

source§

fn load<'async_trait>( context: C, ) -> Pin<Box<dyn Future<Output = Result<SystemExecutionStateView<C>, ViewError>> + Send + 'async_trait>>
where SystemExecutionStateView<C>: 'async_trait,

source§

fn rollback(&mut self)

source§

fn has_pending_changes<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where 'life0: 'async_trait, SystemExecutionStateView<C>: 'async_trait,

source§

fn flush(&mut self, batch: &mut Batch) -> Result<bool, ViewError>

source§

fn clear(&mut self)

Implementors§

source§

impl<C> View<C> for TestBucketQueueView<C>
where C: Context + Send + Sync + Clone + 'static,

source§

impl<C> View<C> for TestCollectionView<C>
where C: Context + Send + Sync + Clone + 'static,

source§

impl<C> View<C> for TestLogView<C>
where C: Context + Send + Sync + Clone + 'static,

source§

impl<C> View<C> for TestMapView<C>
where C: Context + Send + Sync + Clone + 'static,

source§

impl<C> View<C> for TestQueueView<C>
where C: Context + Send + Sync + Clone + 'static,

source§

impl<C> View<C> for TestRegisterView<C>
where C: Context + Send + Sync + Clone + 'static,

source§

impl<C> View<C> for TestSetView<C>
where C: Context + Send + Sync + Clone + 'static,

source§

impl<C> View<C> for KeyValueStoreView<C>
where C: Context + Send + Sync, ViewError: From<<C as Context>::Error>,

source§

impl<C> View<C> for ByteSetView<C>
where C: Context + Send + Sync, ViewError: From<<C as Context>::Error>,

source§

impl<C, I> View<C> for CustomSetView<C, I>
where C: Context + Send + Sync, ViewError: From<<C as Context>::Error>, I: Send + Sync + CustomSerialize,

source§

impl<C, I> View<C> for SetView<C, I>
where C: Context + Send + Sync, ViewError: From<<C as Context>::Error>, I: Send + Sync + Serialize,

source§

impl<C, I, V> View<C> for CustomMapView<C, I, V>

source§

impl<C, I, V> View<C> for MapView<C, I, V>
where C: Context + Send + Sync, ViewError: From<<C as Context>::Error>, I: Sync, V: Send + Sync + Serialize,

source§

impl<C, I, W> View<C> for CollectionView<C, I, W>
where C: Context + Send + Sync, ViewError: From<<C as Context>::Error>, I: Send + Sync + Serialize + DeserializeOwned, W: View<C> + Send + Sync,

source§

impl<C, I, W> View<C> for CustomCollectionView<C, I, W>
where C: Context + Send + Sync, ViewError: From<<C as Context>::Error>, I: Send + Sync, W: View<C> + Send + Sync,

source§

impl<C, I, W> View<C> for ReentrantCollectionView<C, I, W>
where C: Context + Send + Sync, ViewError: From<<C as Context>::Error>, I: Send + Sync + Serialize + DeserializeOwned, W: View<C> + Send + Sync,

source§

impl<C, I, W> View<C> for ReentrantCustomCollectionView<C, I, W>
where C: Context + Send + Sync, ViewError: From<<C as Context>::Error>, I: Send + Sync + CustomSerialize, W: View<C> + Send + Sync,

source§

impl<C, T> View<C> for LogView<C, T>
where C: Context + Send + Sync, ViewError: From<<C as Context>::Error>, T: Send + Sync + Serialize,

source§

impl<C, T> View<C> for QueueView<C, T>
where C: Context + Send + Sync, ViewError: From<<C as Context>::Error>, T: Send + Sync + Serialize,

source§

impl<C, T> View<C> for RegisterView<C, T>

source§

impl<C, T, const N: usize> View<C> for BucketQueueView<C, T, N>

source§

impl<C, V> View<C> for ByteMapView<C, V>
where C: Context + Send + Sync, ViewError: From<<C as Context>::Error>, V: Send + Sync + Serialize,

source§

impl<C, W> View<C> for ByteCollectionView<C, W>
where C: Context + Send + Sync, ViewError: From<<C as Context>::Error>, W: View<C> + Send + Sync,

source§

impl<C, W> View<C> for ReentrantByteCollectionView<C, W>
where C: Context + Send + Sync, ViewError: From<<C as Context>::Error>, W: View<C> + Send + Sync,

source§

impl<C, W, O> View<C> for WrappedHashableContainerView<C, W, O>
where C: Context + Send + Sync, ViewError: From<<C as Context>::Error>, W: HashableView<C> + Send + Sync, O: Serialize + DeserializeOwned + Send + Sync + Copy + PartialEq, <W as HashableView<C>>::Hasher: Hasher<Output = O>,