pub trait AsyncPwm: Sized {
type Error: Error;
type Key;
type Value;
type Options;
type Iter<'a>: Iterator<Item = (&'a Self::Key, &'a EntryValue<Self::Value>)>
where Self: 'a;
type IntoIter: Iterator<Item = (Self::Key, EntryValue<Self::Value>)>;
Show 14 methods
// Required methods
fn new(
options: Self::Options
) -> impl Future<Output = Result<Self, Self::Error>>;
fn is_empty(&self) -> impl Future<Output = bool>;
fn len(&self) -> impl Future<Output = usize>;
fn validate_entry(
&self,
entry: &Entry<Self::Key, Self::Value>
) -> impl Future<Output = Result<(), Self::Error>>;
fn max_batch_size(&self) -> u64;
fn max_batch_entries(&self) -> u64;
fn estimate_size(&self, entry: &Entry<Self::Key, Self::Value>) -> u64;
fn get(
&self,
key: &Self::Key
) -> impl Future<Output = Result<Option<&EntryValue<Self::Value>>, Self::Error>>;
fn contains_key(
&self,
key: &Self::Key
) -> impl Future<Output = Result<bool, Self::Error>>;
fn insert(
&mut self,
key: Self::Key,
value: EntryValue<Self::Value>
) -> impl Future<Output = Result<(), Self::Error>>;
fn remove_entry(
&mut self,
key: &Self::Key
) -> impl Future<Output = Result<Option<(Self::Key, EntryValue<Self::Value>)>, Self::Error>>;
fn rollback(&mut self) -> impl Future<Output = Result<(), Self::Error>>;
fn iter(
&self
) -> impl Future<Output = impl Iterator<Item = (&Self::Key, &EntryValue<Self::Value>)>>;
fn into_iter(
self
) -> impl Future<Output = impl Iterator<Item = (Self::Key, EntryValue<Self::Value>)>>;
}
Expand description
A pending writes manager that can be used to store pending writes in a transaction.
By default, there are two implementations of this trait:
- [
IndexMap
]: A hash map with consistent ordering and fast lookups. - [
BTreeMap
]: A balanced binary tree with ordered keys and fast lookups.
But, users can create their own implementations by implementing this trait. e.g. if you want to implement a recovery transaction manager, you can use a persistent storage to store the pending writes.
Required Associated Types§
Required Methods§
sourcefn new(
options: Self::Options
) -> impl Future<Output = Result<Self, Self::Error>>
fn new( options: Self::Options ) -> impl Future<Output = Result<Self, Self::Error>>
Create a new pending manager with the given options.
sourcefn validate_entry(
&self,
entry: &Entry<Self::Key, Self::Value>
) -> impl Future<Output = Result<(), Self::Error>>
fn validate_entry( &self, entry: &Entry<Self::Key, Self::Value> ) -> impl Future<Output = Result<(), Self::Error>>
Validate if the entry is valid for this database.
e.g.
- If the entry is expired
- If the key or the value is too large
- If the key or the value is empty
- If the key or the value contains invalid characters
- and etc.
sourcefn max_batch_size(&self) -> u64
fn max_batch_size(&self) -> u64
Returns the maximum batch size in bytes
sourcefn max_batch_entries(&self) -> u64
fn max_batch_entries(&self) -> u64
Returns the maximum entries in batch
sourcefn estimate_size(&self, entry: &Entry<Self::Key, Self::Value>) -> u64
fn estimate_size(&self, entry: &Entry<Self::Key, Self::Value>) -> u64
Returns the estimated size of the entry in bytes when persisted in the database.
sourcefn get(
&self,
key: &Self::Key
) -> impl Future<Output = Result<Option<&EntryValue<Self::Value>>, Self::Error>>
fn get( &self, key: &Self::Key ) -> impl Future<Output = Result<Option<&EntryValue<Self::Value>>, Self::Error>>
Returns a reference to the value corresponding to the key.
sourcefn contains_key(
&self,
key: &Self::Key
) -> impl Future<Output = Result<bool, Self::Error>>
fn contains_key( &self, key: &Self::Key ) -> impl Future<Output = Result<bool, Self::Error>>
Returns true if the pending manager contains the key.
sourcefn insert(
&mut self,
key: Self::Key,
value: EntryValue<Self::Value>
) -> impl Future<Output = Result<(), Self::Error>>
fn insert( &mut self, key: Self::Key, value: EntryValue<Self::Value> ) -> impl Future<Output = Result<(), Self::Error>>
Inserts a key-value pair into the er.
sourcefn remove_entry(
&mut self,
key: &Self::Key
) -> impl Future<Output = Result<Option<(Self::Key, EntryValue<Self::Value>)>, Self::Error>>
fn remove_entry( &mut self, key: &Self::Key ) -> impl Future<Output = Result<Option<(Self::Key, EntryValue<Self::Value>)>, Self::Error>>
Removes a key from the pending writes, returning the key-value pair if the key was previously in the pending writes.
sourcefn rollback(&mut self) -> impl Future<Output = Result<(), Self::Error>>
fn rollback(&mut self) -> impl Future<Output = Result<(), Self::Error>>
Rollback the pending writes.