linera_views::context

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

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.

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,