From 5442dc582b7c63d07b356aa3ac95f7d4902b6dad Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Sat, 20 Nov 2021 11:15:04 +0000 Subject: [PATCH] Add a generic ChunkSubmissionTarget trait --- yama/src/chunking.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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.