use crate::{ config, details::Details, repo::{Alias, DeleteToken}, store::{Identifier, StoreError}, }; use futures_util::Stream; use std::fmt::Debug; pub(crate) use self::sled::SledRepo; mod sled; #[tracing::instrument] pub(crate) fn open(config: &config::Sled) -> color_eyre::Result> { let config::Sled { path, cache_capacity, export_path: _, } = config; SledRepo::build(path.clone(), *cache_capacity) } #[derive(Debug, thiserror::Error)] pub(crate) enum RepoError { #[error("Error in sled")] SledError(#[from] self::sled::SledError), } pub(crate) trait BaseRepo { type Bytes: AsRef<[u8]> + From> + Clone; } impl BaseRepo for actix_web::web::Data where T: BaseRepo, { type Bytes = T::Bytes; } #[async_trait::async_trait(?Send)] pub(crate) trait SettingsRepo: BaseRepo { async fn get(&self, key: &'static str) -> Result, RepoError>; } #[async_trait::async_trait(?Send)] pub(crate) trait IdentifierRepo: BaseRepo { async fn details(&self, identifier: &I) -> Result, StoreError>; } #[async_trait::async_trait(?Send)] pub(crate) trait HashRepo: BaseRepo { type Stream: Stream>; async fn size(&self) -> Result; async fn hashes(&self) -> Self::Stream; async fn identifier( &self, hash: Self::Bytes, ) -> Result, StoreError>; async fn variants( &self, hash: Self::Bytes, ) -> Result, StoreError>; async fn motion_identifier( &self, hash: Self::Bytes, ) -> Result, StoreError>; } #[async_trait::async_trait(?Send)] pub(crate) trait AliasRepo: BaseRepo { async fn delete_token(&self, alias: &Alias) -> Result, RepoError>; async fn for_hash(&self, hash: Self::Bytes) -> Result, RepoError>; }