1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//! Runtime storage interfaces and implementations.
use std::sync::Arc;

use crate::types::Error;

pub mod mkvs;

// Re-exports.
pub use self::mkvs::MKVS;

/// Trivial Key/Value storage.
pub trait KeyValue: Send + Sync {
    /// Fetch the value for a specific key.
    fn get(&self, key: Vec<u8>) -> Result<Vec<u8>, Error>;

    /// Store a specific key/value into storage.
    fn insert(&self, key: Vec<u8>, value: Vec<u8>) -> Result<(), Error>;
}

impl<T: ?Sized + KeyValue> KeyValue for Arc<T> {
    fn get(&self, key: Vec<u8>) -> Result<Vec<u8>, Error> {
        KeyValue::get(&**self, key)
    }

    fn insert(&self, key: Vec<u8>, value: Vec<u8>) -> Result<(), Error> {
        KeyValue::insert(&**self, key, value)
    }
}