pub mod file;
#[cfg(feature = "git")]
pub mod git;
pub mod memory;
pub use file::FileNodeStorage;
#[cfg(feature = "git")]
pub use git::GitNodeStorage;
pub use memory::InMemoryNodeStorage;
#[cfg(feature = "rocksdb_storage")]
pub use crate::rocksdb::RocksDBNodeStorage;
use crate::digest::ValueDigest;
use crate::node::ProllyNode;
use std::fmt::{Display, Formatter, LowerHex};
use std::sync::Arc;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum StorageError {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Serialization error: {0}")]
Serialization(#[from] bincode::Error),
#[error("Storage error: {0}")]
Other(String),
}
pub trait NodeStorage<const N: usize>: Send + Sync + Clone {
fn get_node_by_hash(&self, hash: &ValueDigest<N>) -> Option<Arc<ProllyNode<N>>>;
fn insert_node(
&mut self,
hash: ValueDigest<N>,
node: ProllyNode<N>,
) -> Result<(), StorageError>;
fn delete_node(&mut self, hash: &ValueDigest<N>) -> Result<(), StorageError>;
fn save_config(&self, key: &str, config: &[u8]);
fn get_config(&self, key: &str) -> Option<Vec<u8>>;
}
impl<const N: usize> Display for ValueDigest<N> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
for byte in self.0 {
write!(f, "{byte:02x}")?;
}
Ok(())
}
}
impl<const N: usize> LowerHex for ValueDigest<N> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
for byte in self.0 {
write!(f, "{byte:02x}")?;
}
Ok(())
}
}