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 15 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 get_entry(
&self,
key: &Self::Key,
) -> impl Future<Output = Result<Option<(&Self::Key, &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 = Self::Iter<'_>>;
fn into_iter(self) -> impl Future<Output = Self::IntoIter>;
}
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 get_entry(
&self,
key: &Self::Key,
) -> impl Future<Output = Result<Option<(&Self::Key, &EntryValue<Self::Value>)>, Self::Error>>
fn get_entry( &self, key: &Self::Key, ) -> impl Future<Output = Result<Option<(&Self::Key, &EntryValue<Self::Value>)>, Self::Error>>
Returns a reference to the key-value pair 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.
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.