use Clone()able backends only

This commit is contained in:
Alexander Weiss 2022-02-05 20:12:28 +01:00
parent f763e4fb11
commit c963dcf551
6 changed files with 25 additions and 18 deletions

View File

@ -15,21 +15,22 @@ pub enum RepoError<E> {
RepoError(#[from] E),
}
pub struct DecryptBackend<'a, R> {
backend: &'a R,
#[derive(Clone)]
pub struct DecryptBackend<R> {
backend: R,
key: Key,
}
impl<'a, R: ReadBackend> DecryptBackend<'a, R> {
pub fn new(be: &'a R, key: Key) -> Self {
impl<R: ReadBackend> DecryptBackend<R> {
pub fn new(be: &R, key: Key) -> Self {
Self {
backend: be,
backend: be.clone(),
key: key,
}
}
}
impl<'a, R: ReadBackend> ReadBackend for DecryptBackend<'a, R> {
impl<R: ReadBackend> ReadBackend for DecryptBackend<R> {
type Error = RepoError<R::Error>;
fn location(&self) -> &str {

View File

@ -5,6 +5,7 @@ use walkdir::WalkDir;
use super::{FileType, Id, ReadBackend};
#[derive(Clone)]
pub struct LocalBackend {
path: PathBuf,
}

View File

@ -27,7 +27,7 @@ impl FileType {
}
}
pub trait ReadBackend {
pub trait ReadBackend: Clone {
type Error: Send + Sync + std::error::Error + 'static;
fn location(&self) -> &str;

View File

@ -8,6 +8,7 @@ pub type CryptoError = aead::Error;
type Nonce = aead::Nonce<Aes256CtrPoly1305Aes>;
type AeadKey = aead::Key<Aes256CtrPoly1305Aes>;
#[derive(Clone)]
pub struct Key(AeadKey);
impl Key {

View File

@ -3,26 +3,26 @@ use crate::backend::{FileType, ReadBackend};
use crate::id::Id;
use crate::repo::IndexFile;
pub struct AllIndexFiles<'a, BE> {
be: &'a BE,
pub struct AllIndexFiles<BE> {
be: BE,
files: Vec<Id>,
}
impl<'a, BE: ReadBackend> AllIndexFiles<'a, BE> {
pub fn new(be: &'a BE) -> Self {
impl<BE: ReadBackend> AllIndexFiles<BE> {
pub fn new(be: &BE) -> Self {
Self {
be: be,
be: be.clone(),
files: be.list(FileType::Index).unwrap(),
}
}
}
impl<'a, BE: ReadBackend> ReadIndex for AllIndexFiles<'a, BE> {
impl<BE: ReadBackend> ReadIndex for AllIndexFiles<BE> {
fn iter(&self) -> Box<dyn Iterator<Item = IndexEntry> + '_> {
Box::new(
self.files
.iter()
.flat_map(|id| IndexFile::from_backend(self.be, *id).unwrap().into_iter()),
.flat_map(|&id| IndexFile::from_backend(&self.be, id).unwrap().into_iter()),
)
}
}

View File

@ -28,16 +28,20 @@ impl IntoIterator for IndexFile {
fn into_iter(self) -> Self::IntoIter {
Box::new(self.packs.into_iter().flat_map(|p| {
p.blobs.into_iter().map(move |b| IndexEntry::new(p.id,b.to_bi()))
p.blobs
.into_iter()
.map(move |b| IndexEntry::new(p.id, b.to_bi()))
}))
}
}
impl ReadIndex for IndexFile {
fn iter(&self) -> Box<dyn Iterator<Item = IndexEntry> + '_> {
Box::new(self.packs.iter().flat_map(|p| {
p.blobs.iter().map(|b| IndexEntry::new(p.id,b.to_bi()))
}))
Box::new(
self.packs
.iter()
.flat_map(|p| p.blobs.iter().map(|b| IndexEntry::new(p.id, b.to_bi()))),
)
}
}