use async_trait::async_trait;
use mithril_common::StdError;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum AdapterError {
#[error("something wrong happened")]
GeneralError(#[source] StdError),
#[error("problem creating the repository")]
InitializationError(#[source] StdError),
#[error("problem opening the IO stream")]
OpeningStreamError(#[source] StdError),
#[error("problem parsing the IO stream")]
ParsingDataError(#[source] StdError),
#[error("problem when querying the adapter")]
QueryError(#[source] StdError),
}
#[async_trait]
pub trait StoreAdapter: Sync + Send {
type Key;
type Record;
async fn store_record(
&mut self,
key: &Self::Key,
record: &Self::Record,
) -> Result<(), AdapterError>;
async fn get_record(&self, key: &Self::Key) -> Result<Option<Self::Record>, AdapterError>;
async fn record_exists(&self, key: &Self::Key) -> Result<bool, AdapterError>;
async fn get_last_n_records(
&self,
how_many: usize,
) -> Result<Vec<(Self::Key, Self::Record)>, AdapterError>;
async fn remove(&mut self, key: &Self::Key) -> Result<Option<Self::Record>, AdapterError>;
async fn get_iter(&self) -> Result<Box<dyn Iterator<Item = Self::Record> + '_>, AdapterError>;
}