use async_trait::async_trait;
use crate::error::FluxError;
use std::collections::HashMap;
use std::fmt::Debug;
use serde::{Deserialize, Serialize};
use crate::file::key_collection::KeyCollection;
use crate::key::Key;
#[async_trait]
pub trait Flux: Send + Sync + Debug {
async fn initialize(& self) -> Result<(), FluxError> {
Ok(())
}
async fn finalize(&self) -> Result<(), FluxError> {
Ok(())
}
async fn single(&self, _key: &Key) -> Result<(), FluxError> {
Err(FluxError::NotImplementedError("single".into()))
}
async fn batch(&self, keys: &KeyCollection) -> Result<(), FluxError> {
let tasks = keys.into_iter().map(|key| async {
self.single(key).await?;
Ok::<(), FluxError>(())
});
let results = futures::future::join_all(tasks).await;
for result in results {
result?;
}
Ok(())
}
async fn check(&self, _key: &Key) -> Result<Option<String>, FluxError> {
Err(FluxError::NotImplementedError("check".into()))
}
async fn check_batch(&self, keys: &KeyCollection) -> Result<Vec<(String, Option<String>)>, FluxError> {
Err(FluxError::NotImplementedError("check_batch".into()))
}
async fn revert(&self, _key: &Key) -> Result<(), FluxError> {
Err(FluxError::NotImplementedError("revert".into()))
}
async fn revert_batch(&self, keys: &KeyCollection) -> Result<(), FluxError> {
Err(FluxError::NotImplementedError("revert_batch".into()))
}
async fn diff(&self, _key: &Key) -> Result<String, FluxError> {
Err(FluxError::NotImplementedError("diff".into()))
}
async fn diff_batch(&self, keys: &KeyCollection) -> Result<HashMap<String, String>, FluxError> {
Err(FluxError::NotImplementedError("diff_batch".into()))
}
}