Trait linera_views::context::Context

source ·
pub trait Context: Clone {
    type Extra: Clone + Send + Sync;
    type Error: KeyValueStoreError + Send + Sync + 'static;
    type Keys: KeyIterable<Self::Error>;
    type KeyValues: KeyValueIterable<Self::Error>;

    const MAX_VALUE_SIZE: usize;
    const MAX_KEY_SIZE: usize;
Show 20 methods // Required methods fn max_stream_queries(&self) -> usize; fn read_value_bytes<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn contains_key<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<bool, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn contains_keys<'life0, 'async_trait>( &'life0 self, keys: Vec<Vec<u8>>, ) -> Pin<Box<dyn Future<Output = Result<Vec<bool>, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn read_multi_values_bytes<'life0, 'async_trait>( &'life0 self, keys: Vec<Vec<u8>>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Option<Vec<u8>>>, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn find_keys_by_prefix<'life0, 'life1, 'async_trait>( &'life0 self, key_prefix: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<Self::Keys, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn find_key_values_by_prefix<'life0, 'life1, 'async_trait>( &'life0 self, key_prefix: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<Self::KeyValues, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn write_batch<'life0, 'async_trait>( &'life0 self, batch: Batch, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn extra(&self) -> &Self::Extra; fn clone_with_base_key(&self, base_key: Vec<u8>) -> Self; fn base_key(&self) -> Vec<u8> ; // Provided methods fn base_tag(&self, tag: u8) -> Vec<u8> { ... } fn base_tag_index(&self, tag: u8, index: &[u8]) -> Vec<u8> { ... } fn base_index(&self, index: &[u8]) -> Vec<u8> { ... } fn derive_key<I: Serialize>( &self, index: &I, ) -> Result<Vec<u8>, Self::Error> { ... } fn derive_tag_key<I: Serialize>( &self, tag: u8, index: &I, ) -> Result<Vec<u8>, Self::Error> { ... } fn derive_short_key<I: Serialize + ?Sized>( index: &I, ) -> Result<Vec<u8>, Self::Error> { ... } fn deserialize_value<Item: DeserializeOwned>( bytes: &[u8], ) -> Result<Item, Self::Error> { ... } fn read_value<'life0, 'life1, 'async_trait, Item>( &'life0 self, key: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<Item>, Self::Error>> + Send + 'async_trait>> where Item: DeserializeOwned + 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn read_multi_values<'life0, 'async_trait, V>( &'life0 self, keys: Vec<Vec<u8>>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Option<V>>, Self::Error>> + Send + 'async_trait>> where Self::Error: From<Error>, V: 'async_trait + DeserializeOwned + Send, Self: Sync + 'async_trait, 'life0: 'async_trait { ... }
}
Expand description

The context in which a view is operated. Typically, this includes the client to connect to the database and the address of the current entry.

Required Associated Types§

source

type Extra: Clone + Send + Sync

User-provided data to be carried along.

source

type Error: KeyValueStoreError + Send + Sync + 'static

The error type in use by internal operations.

source

type Keys: KeyIterable<Self::Error>

Returns type for key search operations.

source

type KeyValues: KeyValueIterable<Self::Error>

Returns type for key-value search operations.

Required Associated Constants§

source

const MAX_VALUE_SIZE: usize

The maximal size of values that can be stored.

source

const MAX_KEY_SIZE: usize

The maximal size of keys that can be stored.

Required Methods§

source

fn max_stream_queries(&self) -> usize

Retrieves the number of stream queries.

source

fn read_value_bytes<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves a Vec<u8> from the database using the provided key prefixed by the current context.

source

fn contains_key<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<bool, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Tests whether a key exists in the database

source

fn contains_keys<'life0, 'async_trait>( &'life0 self, keys: Vec<Vec<u8>>, ) -> Pin<Box<dyn Future<Output = Result<Vec<bool>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Tests whether a set of keys exist in the database

source

fn read_multi_values_bytes<'life0, 'async_trait>( &'life0 self, keys: Vec<Vec<u8>>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Option<Vec<u8>>>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Retrieves multiple Vec<u8> from the database using the provided keys.

source

fn find_keys_by_prefix<'life0, 'life1, 'async_trait>( &'life0 self, key_prefix: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<Self::Keys, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Finds the keys matching the key_prefix. The key_prefix is not included in the returned keys.

source

fn find_key_values_by_prefix<'life0, 'life1, 'async_trait>( &'life0 self, key_prefix: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<Self::KeyValues, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Finds the (key,value) pairs matching the key_prefix. The key_prefix is not included in the returned keys.

source

fn write_batch<'life0, 'async_trait>( &'life0 self, batch: Batch, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Applies the operations from the batch, persisting the changes.

source

fn extra(&self) -> &Self::Extra

Getter for the user-provided data.

source

fn clone_with_base_key(&self, base_key: Vec<u8>) -> Self

Obtains a similar Context implementation with a different base key.

source

fn base_key(&self) -> Vec<u8>

Getter for the address of the base key.

Provided Methods§

source

fn base_tag(&self, tag: u8) -> Vec<u8>

Concatenates the base key and tag.

source

fn base_tag_index(&self, tag: u8, index: &[u8]) -> Vec<u8>

Concatenates the base key, tag and index.

source

fn base_index(&self, index: &[u8]) -> Vec<u8>

Concatenates the base key and index.

source

fn derive_key<I: Serialize>(&self, index: &I) -> Result<Vec<u8>, Self::Error>

Obtains the Vec<u8> key from the key by serialization and using the base key.

source

fn derive_tag_key<I: Serialize>( &self, tag: u8, index: &I, ) -> Result<Vec<u8>, Self::Error>

Obtains the Vec<u8> key from the key by serialization and using the base_key.

source

fn derive_short_key<I: Serialize + ?Sized>( index: &I, ) -> Result<Vec<u8>, Self::Error>

Obtains the short Vec<u8> key from the key by serialization.

source

fn deserialize_value<Item: DeserializeOwned>( bytes: &[u8], ) -> Result<Item, Self::Error>

Deserialize bytes into type Item.

source

fn read_value<'life0, 'life1, 'async_trait, Item>( &'life0 self, key: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<Item>, Self::Error>> + Send + 'async_trait>>
where Item: DeserializeOwned + 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves a generic Item from the database using the provided key prefixed by the current context. The Item is deserialized using bcs.

source

fn read_multi_values<'life0, 'async_trait, V>( &'life0 self, keys: Vec<Vec<u8>>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Option<V>>, Self::Error>> + Send + 'async_trait>>
where Self::Error: From<Error>, V: 'async_trait + DeserializeOwned + Send, Self: Sync + 'async_trait, 'life0: 'async_trait,

Reads multiple keys and deserializes the results if present.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<E, S> Context for ViewContext<E, S>
where E: Clone + Send + Sync, S: RestrictedKeyValueStore + Clone + Send + Sync, S::Error: From<Error> + Send + Sync + Error + 'static,

source§

const MAX_VALUE_SIZE: usize = S::MAX_VALUE_SIZE

source§

const MAX_KEY_SIZE: usize = S::MAX_KEY_SIZE

§

type Extra = E

§

type Error = <S as WithError>::Error

§

type Keys = <S as ReadableKeyValueStore>::Keys

§

type KeyValues = <S as ReadableKeyValueStore>::KeyValues