puffin/puffin_manager/
fs_puffin_manager.rsmod dir_meta;
mod reader;
mod writer;
use async_trait::async_trait;
pub use reader::FsPuffinReader;
pub use writer::FsPuffinWriter;
use crate::error::Result;
use crate::puffin_manager::cache::PuffinMetadataCacheRef;
use crate::puffin_manager::file_accessor::PuffinFileAccessor;
use crate::puffin_manager::stager::Stager;
use crate::puffin_manager::PuffinManager;
#[derive(Clone)]
pub struct FsPuffinManager<S, F> {
stager: S,
puffin_file_accessor: F,
puffin_metadata_cache: Option<PuffinMetadataCacheRef>,
}
impl<S, F> FsPuffinManager<S, F> {
pub fn new(stager: S, puffin_file_accessor: F) -> Self {
Self {
stager,
puffin_file_accessor,
puffin_metadata_cache: None,
}
}
pub fn with_puffin_metadata_cache(
mut self,
puffin_metadata_cache: Option<PuffinMetadataCacheRef>,
) -> Self {
self.puffin_metadata_cache = puffin_metadata_cache;
self
}
}
#[async_trait]
impl<S, F> PuffinManager for FsPuffinManager<S, F>
where
F: PuffinFileAccessor + Clone,
S: Stager<FileHandle = F::FileHandle> + Clone + 'static,
{
type Reader = FsPuffinReader<S, F>;
type Writer = FsPuffinWriter<S, F::Writer>;
type FileHandle = F::FileHandle;
async fn reader(&self, handle: &Self::FileHandle) -> Result<Self::Reader> {
Ok(FsPuffinReader::new(
handle.clone(),
self.stager.clone(),
self.puffin_file_accessor.clone(),
self.puffin_metadata_cache.clone(),
))
}
async fn writer(&self, handle: &Self::FileHandle) -> Result<Self::Writer> {
let writer = self.puffin_file_accessor.writer(handle).await?;
Ok(FsPuffinWriter::new(
handle.clone(),
self.stager.clone(),
writer,
))
}
}