Trait View

Source
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§

Source

const NUM_INIT_KEYS: usize

The number of keys used for the initialization

Required Associated Types§

Source

type Context: Context

The type of context stored in this view

Required Methods§

Source

fn context(&self) -> Self::Context

Obtains a mutable reference to the internal context.

Source

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

Creates the keys needed for loading the view

Source

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

Loads a view from the values

Source

fn rollback(&mut self)

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

Source

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.

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 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.

Source

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§

Source

fn load( context: Self::Context, ) -> impl Future<Output = Result<Self, ViewError>> + Send + Sync

Loads a view

Source

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

Builds a trivial view that is already deleted

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.

Implementations on Foreign Types§

Source§

impl<C> View for ChainStateView<C>
where ReentrantCollectionView<C, AccountOwner, PendingBlobsView<C>>: View<Context = C>, ExecutionStateView<C>: View<Context = C>, LogView<C, CryptoHash>: View<Context = C>, LogView<C, ChainAndHeight>: View<Context = C>, RegisterView<C, Option<CryptoHash>>: View<Context = C>, RegisterView<C, HashMap<Secp256k1PublicKey, u64>>: View<Context = C>, C: Context + Clone + 'static, ReentrantCollectionView<C, ChainId, InboxStateView<C>>: View<Context = C>, RegisterView<C, ChainTipState>: View<Context = C>, ReentrantCollectionView<C, ChainId, OutboxStateView<C>>: View<Context = C>, MapView<C, StreamId, u32>: View<Context = C>, ChainManager<C>: View<Context = C>, RegisterView<C, BTreeMap<BlockHeight, u32>>: View<Context = C>, RegisterView<C, BTreeSet<ChainId>>: View<Context = C>, PendingBlobsView<C>: View<Context = C>, MapView<C, BlockHeight, CryptoHash>: View<Context = C>,

Source§

const NUM_INIT_KEYS: usize

Source§

type Context = C

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§

async fn load(context: C) -> Result<ChainStateView<C>, ViewError>

Source§

fn rollback(&mut self)

Source§

async fn has_pending_changes(&self) -> bool

Source§

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

Source§

fn post_save(&mut self)

Source§

fn clear(&mut self)

Source§

impl<C> View for ChainManager<C>
where MapView<C, BlobId, Blob>: View<Context = C>, C: 'static + Context + Clone, RegisterView<C, Option<LockingBlock>>: View<Context = C>, RegisterView<C, ChainOwnership>: View<Context = C>, RegisterView<C, Option<GenericCertificate<Timeout>>>: View<Context = C>, RegisterView<C, Option<Vote<ConfirmedBlock>>>: View<Context = C>, RegisterView<C, u64>: View<Context = C>, RegisterView<C, Option<Vote<ValidatedBlock>>>: View<Context = C>, RegisterView<C, Option<Vote<Timeout>>>: View<Context = C>, RegisterView<C, Option<WeightedAliasIndex<u64>>>: View<Context = C>, RegisterView<C, Option<Timestamp>>: View<Context = C>, RegisterView<C, Round>: View<Context = C>, RegisterView<C, Option<BlockProposal>>: View<Context = C>, RegisterView<C, BTreeMap<AccountOwner, u64>>: View<Context = C>,

Source§

const NUM_INIT_KEYS: usize

Source§

type Context = C

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§

async fn load(context: C) -> Result<ChainManager<C>, ViewError>

Source§

fn rollback(&mut self)

Source§

async fn has_pending_changes(&self) -> bool

Source§

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

Source§

fn post_save(&mut self)

Source§

fn clear(&mut self)

Source§

impl<C> View for ExecutionStateView<C>
where C: Context, HistoricallyHashableView<C, ExecutionStateViewInner<C>>: View<Context = C>,

Source§

const NUM_INIT_KEYS: usize = <HistoricallyHashableView<C, ExecutionStateViewInner<C>> as linera_views::views::View>::NUM_INIT_KEYS

Source§

type Context = C

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§

async fn load(context: C) -> Result<ExecutionStateView<C>, ViewError>

Source§

fn rollback(&mut self)

Source§

async fn has_pending_changes(&self) -> bool

Source§

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

Source§

fn post_save(&mut self)

Source§

fn clear(&mut self)

Source§

impl<C> View for SystemExecutionStateView<C>
where C: Context, MapView<C, AccountOwner, Amount>: View<Context = C>, RegisterView<C, Option<ChainId>>: View<Context = C>, RegisterView<C, Timestamp>: View<Context = C>, RegisterView<C, Option<ChainDescription>>: View<Context = C>, RegisterView<C, bool>: View<Context = C>, RegisterView<C, BTreeMap<Epoch, Committee>>: View<Context = C>, RegisterView<C, ApplicationPermissions>: View<Context = C>, SetView<C, BlobId>: View<Context = C>, RegisterView<C, ChainOwnership>: View<Context = C>, MapView<C, (ChainId, StreamId), EventSubscriptions>: View<Context = C>, RegisterView<C, Epoch>: View<Context = C>, MapView<C, StreamId, u32>: View<Context = C>, RegisterView<C, Amount>: View<Context = C>,

Source§

const NUM_INIT_KEYS: usize

Source§

type Context = C

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§

async fn load(context: C) -> Result<SystemExecutionStateView<C>, ViewError>

Source§

fn rollback(&mut self)

Source§

async fn has_pending_changes(&self) -> bool

Source§

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

Source§

fn post_save(&mut self)

Source§

fn clear(&mut self)

Implementors§

Source§

impl<C> View for TestBucketQueueView<C>
where C: Context, BucketQueueView<C, u16, 2>: View<Context = C>,

Source§

const NUM_INIT_KEYS: usize = <BucketQueueView<C, u16, 2> as linera_views::views::View>::NUM_INIT_KEYS

Source§

type Context = C

Source§

impl<C> View for TestCollectionView<C>
where C: Context, CollectionView<C, i32, RegisterView<C, String>>: View<Context = C>,

Source§

const NUM_INIT_KEYS: usize = <CollectionView<C, i32, RegisterView<C, String>> as linera_views::views::View>::NUM_INIT_KEYS

Source§

type Context = C

Source§

impl<C> View for TestLogView<C>
where C: Context, LogView<C, u16>: View<Context = C>,

Source§

const NUM_INIT_KEYS: usize = <LogView<C, u16> as linera_views::views::View>::NUM_INIT_KEYS

Source§

type Context = C

Source§

impl<C> View for TestMapView<C>
where C: Context, MapView<C, i32, String>: View<Context = C>,

Source§

const NUM_INIT_KEYS: usize = <MapView<C, i32, String> as linera_views::views::View>::NUM_INIT_KEYS

Source§

type Context = C

Source§

impl<C> View for TestQueueView<C>
where C: Context, QueueView<C, u16>: View<Context = C>,

Source§

const NUM_INIT_KEYS: usize = <QueueView<C, u16> as linera_views::views::View>::NUM_INIT_KEYS

Source§

type Context = C

Source§

impl<C> View for TestRegisterView<C>
where C: Context, RegisterView<C, u8>: View<Context = C>,

Source§

const NUM_INIT_KEYS: usize = <RegisterView<C, u8> as linera_views::views::View>::NUM_INIT_KEYS

Source§

type Context = C

Source§

impl<C> View for TestSetView<C>
where C: Context, SetView<C, i32>: View<Context = C>,

Source§

const NUM_INIT_KEYS: usize = <SetView<C, i32> as linera_views::views::View>::NUM_INIT_KEYS

Source§

type Context = C

Source§

impl<C> View for KeyValueStoreView<C>
where C: Context,

Source§

impl<C> View for ByteSetView<C>
where C: Context,

Source§

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

Source§

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

Source§

impl<C, I, V> View for CustomMapView<C, I, V>
where C: Context, I: CustomSerialize + Send + Sync, V: Serialize + Clone + Send + Sync,

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<I, W> View for ReentrantCollectionView<<W as View>::Context, I, W>

Source§

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

Source§

impl<W> View for ByteCollectionView<<W as View>::Context, W>
where W: View,

Source§

impl<W> View for HistoricallyHashableView<<W as View>::Context, W>
where W: View,

Source§

impl<W> View for ReentrantByteCollectionView<<W as View>::Context, W>
where W: View,

Source§

impl<W, I> View for CollectionView<<W as View>::Context, I, W>

Source§

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