use async_trait::async_trait;
use std::{
collections::HashMap,
fmt::{Debug, Display},
io,
};
use crate::{
entry::EntryId, read_filter::ReadFilter, sink::message::MessageId, utils::DisplayDebug,
};
#[async_trait]
pub trait ExternalSave: Debug + Send + Sync {
async fn save_read_filter(
&mut self,
read_filter: &dyn ReadFilter,
) -> Result<(), ExternalSaveError>;
async fn save_entry_to_msg_map(
&mut self,
map: &HashMap<EntryId, MessageId>,
) -> Result<(), ExternalSaveError>;
}
#[allow(missing_docs)] #[derive(thiserror::Error, Debug)]
#[error("Can't save externally{}{}", .path.is_some().then_some(": ").unwrap_or_default(), if let Some(path) = .path.as_ref() { path as &dyn Display } else { &"" })]
pub struct ExternalSaveError {
pub source: io::Error,
pub path: Option<Box<dyn DisplayDebug + Send + Sync>>,
}