mod memory;
mod typed;
pub use memory::MemoryStore;
pub use typed::{ChunkGet, ChunkHas, ChunkPut, SyncChunkGet, SyncChunkHas, SyncChunkPut};
use crate::bmt::DEFAULT_BODY_SIZE;
use crate::chunk::{AnyChunk, ChunkAddress};
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum ChunkStoreError {
#[error("chunk not found: {address_hex}")]
NotFound {
address_hex: String,
},
#[error("{0}")]
Other(String),
}
impl ChunkStoreError {
pub fn not_found(address: &ChunkAddress) -> Self {
Self::NotFound {
address_hex: format!("{address}"),
}
}
}
#[derive(Debug)]
pub struct NullLoader<const BODY_SIZE: usize = DEFAULT_BODY_SIZE>;
impl<const BODY_SIZE: usize> SyncChunkGet<BODY_SIZE> for NullLoader<BODY_SIZE> {
type Error = ChunkStoreError;
fn get(&self, address: &ChunkAddress) -> Result<AnyChunk<BODY_SIZE>, Self::Error> {
Err(ChunkStoreError::not_found(address))
}
}