Files
lattice/lattice-store/src/store.rs
T

36 lines
741 B
Rust

//! The main KV store
use std::collections::HashMap;
/// A log-based Key-Value store.
///
/// The store is a dynamic "view" generated by replaying entries.
pub struct Store {
data: HashMap<Vec<u8>, Vec<u8>>,
}
impl Store {
/// Create a new empty store.
pub fn new() -> Self {
Self {
data: HashMap::new(),
}
}
/// Get a value by key.
pub fn get(&self, key: &[u8]) -> Option<&[u8]> {
self.data.get(key).map(|v| v.as_slice())
}
/// Set a value (this would normally go through the log).
pub fn set(&mut self, key: Vec<u8>, value: Vec<u8>) {
self.data.insert(key, value);
}
}
impl Default for Store {
fn default() -> Self {
Self::new()
}
}