mirror of
https://github.com/vacp2p/pmtree.git
synced 2026-04-16 03:00:32 -04:00
29 lines
805 B
Rust
29 lines
805 B
Rust
use crate::*;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
/// Trait that must be implemented for a Database
|
|
pub trait Database {
|
|
/// Config for database. Default is necessary for a default() pmtree function
|
|
type Config: Default;
|
|
|
|
/// Creates new instance of db
|
|
fn new(config: Self::Config) -> PmtreeResult<Self>
|
|
where
|
|
Self: Sized;
|
|
|
|
/// Loades existing db (existence check required)
|
|
fn load(config: Self::Config) -> PmtreeResult<Self>
|
|
where
|
|
Self: Sized;
|
|
|
|
/// Returns value from db by the key
|
|
fn get(&self, key: DBKey) -> PmtreeResult<Option<Value>>;
|
|
|
|
/// Puts the value to the db by the key
|
|
fn put(&mut self, key: DBKey, value: Value) -> PmtreeResult<()>;
|
|
|
|
/// Batc
|
|
fn put_batch(&mut self, subtree: HashMap<DBKey, Value>) -> PmtreeResult<()>;
|
|
}
|