diff --git a/yama/src/chunking.rs b/yama/src/chunking.rs index 286fca3..98780a7 100644 --- a/yama/src/chunking.rs +++ b/yama/src/chunking.rs @@ -35,6 +35,23 @@ pub const FASTCDC_AVG: usize = 1024 * 1024; // 8 MiB pub const FASTCDC_MAX: usize = 8 * 1024 * 1024; +pub trait ChunkSubmissionTarget { + fn submit(&self, chunk_id: ChunkId, chunk_data: &[u8]) -> anyhow::Result<()>; +} + +impl ChunkSubmissionTarget for Pile { + fn submit(&self, chunk_id: ChunkId, chunk_data: &[u8]) -> anyhow::Result<()> { + self.submit_chunk(chunk_id, chunk_data) + } +} + +impl ChunkSubmissionTarget for crossbeam_channel::Sender<(ChunkId, Vec)> { + fn submit(&self, chunk_id: ChunkId, chunk_data: &[u8]) -> anyhow::Result<()> { + self.send((chunk_id, chunk_data.to_vec())) + .map_err(|_| anyhow::anyhow!("Failed to send to pipeline.")) + } +} + /// A chunker that will generate nested chunks of chunk references if there is that much data /// to store. /// The root RecursiveChunker is fed data bytes.