Trait Pwm

Source
pub trait Pwm: Sized {
    type Error: Error;
    type Key;
    type Value;
    type Iter<'a>: Iterator<Item = (&'a Self::Key, &'a EntryValue<Self::Value>)>
       where Self: 'a;
    type IntoIter: Iterator<Item = (Self::Key, EntryValue<Self::Value>)>;
    type Options;

Show 15 methods // Required methods fn new(options: Self::Options) -> Result<Self, Self::Error>; fn is_empty(&self) -> bool; fn len(&self) -> usize; fn validate_entry( &self, entry: &Entry<Self::Key, Self::Value>, ) -> 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, ) -> Result<Option<&EntryValue<Self::Value>>, Self::Error>; fn get_entry( &self, key: &Self::Key, ) -> Result<Option<(&Self::Key, &EntryValue<Self::Value>)>, Self::Error>; fn contains_key(&self, key: &Self::Key) -> Result<bool, Self::Error>; fn insert( &mut self, key: Self::Key, value: EntryValue<Self::Value>, ) -> Result<(), Self::Error>; fn remove_entry( &mut self, key: &Self::Key, ) -> Result<Option<(Self::Key, EntryValue<Self::Value>)>, Self::Error>; fn iter(&self) -> Self::Iter<'_>; fn into_iter(self) -> Self::IntoIter; fn rollback(&mut self) -> Result<(), Self::Error>;
}
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§

Source

type Error: Error

The error type returned by the conflict manager.

Source

type Key

The key type.

Source

type Value

The value type.

Source

type Iter<'a>: Iterator<Item = (&'a Self::Key, &'a EntryValue<Self::Value>)> where Self: 'a

The iterator type.

Source

type IntoIter: Iterator<Item = (Self::Key, EntryValue<Self::Value>)>

The IntoIterator type.

Source

type Options

The options type used to create the pending manager.

Required Methods§

Source

fn new(options: Self::Options) -> Result<Self, Self::Error>

Create a new pending manager with the given options.

Source

fn is_empty(&self) -> bool

Returns true if the buffer is empty.

Source

fn len(&self) -> usize

Returns the number of elements in the buffer.

Source

fn validate_entry( &self, entry: &Entry<Self::Key, Self::Value>, ) -> 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.
Source

fn max_batch_size(&self) -> u64

Returns the maximum batch size in bytes

Source

fn max_batch_entries(&self) -> u64

Returns the maximum entries in batch

Source

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.

Source

fn get( &self, key: &Self::Key, ) -> Result<Option<&EntryValue<Self::Value>>, Self::Error>

Returns a reference to the value corresponding to the key.

Source

fn get_entry( &self, key: &Self::Key, ) -> Result<Option<(&Self::Key, &EntryValue<Self::Value>)>, Self::Error>

Returns a reference to the key-value pair corresponding to the key.

Source

fn contains_key(&self, key: &Self::Key) -> Result<bool, Self::Error>

Returns true if the pending manager contains the key.

Source

fn insert( &mut self, key: Self::Key, value: EntryValue<Self::Value>, ) -> Result<(), Self::Error>

Inserts a key-value pair into the er.

Source

fn remove_entry( &mut self, key: &Self::Key, ) -> 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.

Source

fn iter(&self) -> Self::Iter<'_>

Returns an iterator over the pending writes.

Source

fn into_iter(self) -> Self::IntoIter

Returns an iterator that consumes the pending writes.

Source

fn rollback(&mut self) -> 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.

Implementations on Foreign Types§

Source§

impl<K, V> Pwm for BTreeMap<K, EntryValue<V>>
where K: Ord,

Source§

type Error = Infallible

Source§

type Key = K

Source§

type Value = V

Source§

type Iter<'a> = Iter<'a, K, EntryValue<V>> where BTreeMap<K, EntryValue<V>>: 'a

Source§

type IntoIter = IntoIter<K, EntryValue<V>>

Source§

type Options = ()

Source§

fn new( _: <BTreeMap<K, EntryValue<V>> as Pwm>::Options, ) -> Result<BTreeMap<K, EntryValue<V>>, <BTreeMap<K, EntryValue<V>> as Pwm>::Error>

Source§

fn is_empty(&self) -> bool

Source§

fn len(&self) -> usize

Source§

fn validate_entry( &self, _entry: &Entry<<BTreeMap<K, EntryValue<V>> as Pwm>::Key, <BTreeMap<K, EntryValue<V>> as Pwm>::Value>, ) -> Result<(), <BTreeMap<K, EntryValue<V>> as Pwm>::Error>

Source§

fn max_batch_size(&self) -> u64

Source§

fn max_batch_entries(&self) -> u64

Source§

fn estimate_size( &self, _entry: &Entry<<BTreeMap<K, EntryValue<V>> as Pwm>::Key, <BTreeMap<K, EntryValue<V>> as Pwm>::Value>, ) -> u64

Source§

fn get( &self, key: &K, ) -> Result<Option<&EntryValue<<BTreeMap<K, EntryValue<V>> as Pwm>::Value>>, <BTreeMap<K, EntryValue<V>> as Pwm>::Error>

Source§

fn get_entry( &self, key: &<BTreeMap<K, EntryValue<V>> as Pwm>::Key, ) -> Result<Option<(&<BTreeMap<K, EntryValue<V>> as Pwm>::Key, &EntryValue<<BTreeMap<K, EntryValue<V>> as Pwm>::Value>)>, <BTreeMap<K, EntryValue<V>> as Pwm>::Error>

Source§

fn contains_key( &self, key: &K, ) -> Result<bool, <BTreeMap<K, EntryValue<V>> as Pwm>::Error>

Source§

fn insert( &mut self, key: K, value: EntryValue<<BTreeMap<K, EntryValue<V>> as Pwm>::Value>, ) -> Result<(), <BTreeMap<K, EntryValue<V>> as Pwm>::Error>

Source§

fn remove_entry( &mut self, key: &K, ) -> Result<Option<(K, EntryValue<<BTreeMap<K, EntryValue<V>> as Pwm>::Value>)>, <BTreeMap<K, EntryValue<V>> as Pwm>::Error>

Source§

fn iter(&self) -> <BTreeMap<K, EntryValue<V>> as Pwm>::Iter<'_>

Source§

fn into_iter(self) -> <BTreeMap<K, EntryValue<V>> as Pwm>::IntoIter

Source§

fn rollback(&mut self) -> Result<(), <BTreeMap<K, EntryValue<V>> as Pwm>::Error>

Source§

impl<K, V, S> Pwm for IndexMap<K, EntryValue<V>, S>
where K: Eq + Hash, S: BuildHasher + Default,

Source§

type Error = Infallible

Source§

type Key = K

Source§

type Value = V

Source§

type Iter<'a> = Iter<'a, K, EntryValue<V>> where IndexMap<K, EntryValue<V>, S>: 'a

Source§

type IntoIter = IntoIter<K, EntryValue<V>>

Source§

type Options = Option<S>

Source§

fn new( options: <IndexMap<K, EntryValue<V>, S> as Pwm>::Options, ) -> Result<IndexMap<K, EntryValue<V>, S>, <IndexMap<K, EntryValue<V>, S> as Pwm>::Error>

Source§

fn is_empty(&self) -> bool

Source§

fn len(&self) -> usize

Source§

fn validate_entry( &self, _entry: &Entry<<IndexMap<K, EntryValue<V>, S> as Pwm>::Key, <IndexMap<K, EntryValue<V>, S> as Pwm>::Value>, ) -> Result<(), <IndexMap<K, EntryValue<V>, S> as Pwm>::Error>

Source§

fn max_batch_size(&self) -> u64

Source§

fn max_batch_entries(&self) -> u64

Source§

fn estimate_size( &self, _entry: &Entry<<IndexMap<K, EntryValue<V>, S> as Pwm>::Key, <IndexMap<K, EntryValue<V>, S> as Pwm>::Value>, ) -> u64

Source§

fn get( &self, key: &K, ) -> Result<Option<&EntryValue<V>>, <IndexMap<K, EntryValue<V>, S> as Pwm>::Error>

Source§

fn get_entry( &self, key: &<IndexMap<K, EntryValue<V>, S> as Pwm>::Key, ) -> Result<Option<(&<IndexMap<K, EntryValue<V>, S> as Pwm>::Key, &EntryValue<<IndexMap<K, EntryValue<V>, S> as Pwm>::Value>)>, <IndexMap<K, EntryValue<V>, S> as Pwm>::Error>

Source§

fn contains_key( &self, key: &K, ) -> Result<bool, <IndexMap<K, EntryValue<V>, S> as Pwm>::Error>

Source§

fn insert( &mut self, key: K, value: EntryValue<V>, ) -> Result<(), <IndexMap<K, EntryValue<V>, S> as Pwm>::Error>

Source§

fn remove_entry( &mut self, key: &K, ) -> Result<Option<(K, EntryValue<V>)>, <IndexMap<K, EntryValue<V>, S> as Pwm>::Error>

Source§

fn iter(&self) -> <IndexMap<K, EntryValue<V>, S> as Pwm>::Iter<'_>

Source§

fn into_iter(self) -> <IndexMap<K, EntryValue<V>, S> as Pwm>::IntoIter

Source§

fn rollback( &mut self, ) -> Result<(), <IndexMap<K, EntryValue<V>, S> as Pwm>::Error>

Implementors§