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§
sourcetype Error: KeyValueStoreError + Send + Sync + 'static
type Error: KeyValueStoreError + Send + Sync + 'static
The error type in use by internal operations.
sourcetype Keys: KeyIterable<Self::Error>
type Keys: KeyIterable<Self::Error>
Returns type for key search operations.
sourcetype KeyValues: KeyValueIterable<Self::Error>
type KeyValues: KeyValueIterable<Self::Error>
Returns type for key-value search operations.
Required Associated Constants§
sourceconst MAX_VALUE_SIZE: usize
const MAX_VALUE_SIZE: usize
The maximal size of values that can be stored.
sourceconst MAX_KEY_SIZE: usize
const MAX_KEY_SIZE: usize
The maximal size of keys that can be stored.
Required Methods§
sourcefn max_stream_queries(&self) -> usize
fn max_stream_queries(&self) -> usize
Retrieves the number of stream queries.
sourcefn 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 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.
sourcefn 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_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
sourcefn 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 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
sourcefn 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 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
.
sourcefn 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_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.
sourcefn 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 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.
sourcefn 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 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.
sourcefn clone_with_base_key(&self, base_key: Vec<u8>) -> Self
fn clone_with_base_key(&self, base_key: Vec<u8>) -> Self
Obtains a similar Context
implementation with a different base key.
Provided Methods§
sourcefn base_tag_index(&self, tag: u8, index: &[u8]) -> Vec<u8> ⓘ
fn base_tag_index(&self, tag: u8, index: &[u8]) -> Vec<u8> ⓘ
Concatenates the base key, tag and index.
sourcefn derive_key<I: Serialize>(&self, index: &I) -> Result<Vec<u8>, Self::Error>
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.
sourcefn derive_tag_key<I: Serialize>(
&self,
tag: u8,
index: &I,
) -> Result<Vec<u8>, Self::Error>
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
.
sourcefn derive_short_key<I: Serialize + ?Sized>(
index: &I,
) -> Result<Vec<u8>, Self::Error>
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.
sourcefn deserialize_value<Item: DeserializeOwned>(
bytes: &[u8],
) -> Result<Item, Self::Error>
fn deserialize_value<Item: DeserializeOwned>( bytes: &[u8], ) -> Result<Item, Self::Error>
Deserialize bytes
into type Item
.
sourcefn 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_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
.