Add a generic ChunkSubmissionTarget trait

This commit is contained in:
Olivier 'reivilibre' 2021-11-20 11:15:04 +00:00
parent 3c6c19e126
commit 5442dc582b
1 changed files with 17 additions and 0 deletions

View File

@ -35,6 +35,23 @@ pub const FASTCDC_AVG: usize = 1024 * 1024;
// 8 MiB // 8 MiB
pub const FASTCDC_MAX: usize = 8 * 1024 * 1024; pub const FASTCDC_MAX: usize = 8 * 1024 * 1024;
pub trait ChunkSubmissionTarget {
fn submit(&self, chunk_id: ChunkId, chunk_data: &[u8]) -> anyhow::Result<()>;
}
impl<RP: RawPile> ChunkSubmissionTarget for Pile<RP> {
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<u8>)> {
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 /// A chunker that will generate nested chunks of chunk references if there is that much data
/// to store. /// to store.
/// The root RecursiveChunker is fed data bytes. /// The root RecursiveChunker is fed data bytes.