Trait linera_views::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 Self: 'async_trait,
             'life0: '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 Self: 'async_trait, 'life0: '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.

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::Error>,

source§

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

source§

impl<C, I> View<C> for CustomSetView<C, I>

source§

impl<C, I> View<C> for SetView<C, I>
where C: Context + Send + Sync, ViewError: From<C::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::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::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::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::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::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::Error>, T: Send + Sync + Serialize,

source§

impl<C, T> View<C> for QueueView<C, T>
where C: Context + Send + Sync, ViewError: From<C::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::Error>, V: Send + Sync + Serialize,

source§

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

source§

impl<C, W> View<C> for ReentrantByteCollectionView<C, W>
where C: Context + Send + Sync, ViewError: From<C::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::Error>, W: HashableView<C> + Send + Sync, O: Serialize + DeserializeOwned + Send + Sync + Copy + PartialEq, W::Hasher: Hasher<Output = O>,