nectar_primitives/store/
mod.rs1mod memory;
9mod typed;
10
11pub use memory::MemoryStore;
12pub use typed::{ChunkGet, ChunkHas, ChunkPut, SyncChunkGet, SyncChunkHas, SyncChunkPut};
13
14use crate::bmt::DEFAULT_BODY_SIZE;
15use crate::chunk::{AnyChunk, ChunkAddress};
16
17#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
19pub enum ChunkStoreError {
20 #[error("chunk not found: {address_hex}")]
22 NotFound {
23 address_hex: String,
25 },
26 #[error("{0}")]
28 Other(String),
29}
30
31impl ChunkStoreError {
32 pub fn not_found(address: &ChunkAddress) -> Self {
34 Self::NotFound {
35 address_hex: format!("{address}"),
36 }
37 }
38}
39
40#[derive(Debug)]
45pub struct NullLoader<const BODY_SIZE: usize = DEFAULT_BODY_SIZE>;
46
47impl<const BODY_SIZE: usize> SyncChunkGet<BODY_SIZE> for NullLoader<BODY_SIZE> {
48 type Error = ChunkStoreError;
49
50 fn get(&self, address: &ChunkAddress) -> Result<AnyChunk<BODY_SIZE>, Self::Error> {
51 Err(ChunkStoreError::not_found(address))
52 }
53}