Trait txn_core::sync::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 14 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 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 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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

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

§

type Error = Infallible

§

type Key = K

§

type Value = V

§

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

§

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

§

type Options = ()

source§

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

source§

fn is_empty(&self) -> bool

source§

fn len(&self) -> usize

source§

fn validate_entry( &self, _entry: &Entry<Self::Key, Self::Value> ) -> Result<(), Self::Error>

source§

fn max_batch_size(&self) -> u64

source§

fn max_batch_entries(&self) -> u64

source§

fn estimate_size(&self, _entry: &Entry<Self::Key, Self::Value>) -> u64

source§

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

source§

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

source§

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

source§

fn remove_entry( &mut self, key: &K ) -> Result<Option<(K, EntryValue<Self::Value>)>, Self::Error>

source§

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

source§

fn into_iter(self) -> Self::IntoIter

source§

fn rollback(&mut self) -> Result<(), Self::Error>

source§

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

§

type Error = Infallible

§

type Key = K

§

type Value = V

§

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

§

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

§

type Options = Option<S>

source§

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

source§

fn is_empty(&self) -> bool

source§

fn len(&self) -> usize

source§

fn validate_entry( &self, _entry: &Entry<Self::Key, Self::Value> ) -> Result<(), Self::Error>

source§

fn max_batch_size(&self) -> u64

source§

fn max_batch_entries(&self) -> u64

source§

fn estimate_size(&self, _entry: &Entry<Self::Key, Self::Value>) -> u64

source§

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

source§

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

source§

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

source§

fn remove_entry( &mut self, key: &K ) -> Result<Option<(K, EntryValue<V>)>, Self::Error>

source§

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

source§

fn into_iter(self) -> Self::IntoIter

source§

fn rollback(&mut self) -> Result<(), Self::Error>

Implementors§