Skip to main content

commonware_storage/qmdb/
operation.rs

1use crate::mmr::Location;
2use core::{fmt::Debug, hash::Hash, ops::Deref};
3
4/// Trait bound for key types used in QMDB operations. Satisfied by both fixed-size keys
5/// (`Array` types) and variable-length keys (`Vec<u8>`).
6pub trait Key:
7    Clone + Send + Sync + 'static + Eq + Ord + Hash + AsRef<[u8]> + Deref<Target = [u8]> + Debug
8{
9}
10
11impl<T> Key for T where
12    T: Clone + Send + Sync + 'static + Eq + Ord + Hash + AsRef<[u8]> + Deref<Target = [u8]> + Debug
13{
14}
15
16/// An operation that can be applied to a database.
17pub trait Operation {
18    /// The key type for this operation.
19    type Key: Key;
20
21    /// Returns the key if this operation involves a key, None otherwise.
22    fn key(&self) -> Option<&Self::Key>;
23
24    /// If this operation updates its key's value.
25    fn is_update(&self) -> bool;
26
27    /// If this operation deletes its key's value.
28    fn is_delete(&self) -> bool;
29
30    /// The inactivity floor location if this operation is a commit operation with a floor value,
31    /// None otherwise.
32    fn has_floor(&self) -> Option<Location>;
33}
34
35/// A trait for operations used by database variants that support commit operations.
36pub trait Committable {
37    /// If this operation is a commit operation.
38    fn is_commit(&self) -> bool;
39}