feat: mv write_util out of Federate trait for allowing creation of trait objs

This commit is contained in:
Aravinth Manivannan 2022-05-17 20:11:35 +05:30
parent 882fde7d20
commit 519855a7c3
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
2 changed files with 8 additions and 16 deletions

View file

@ -19,7 +19,6 @@ use std::path::Path;
use std::result::Result;
use async_trait::async_trait;
use serde::Serialize;
use db_core::prelude::*;
@ -27,19 +26,12 @@ use db_core::prelude::*;
pub mod tests;
#[async_trait]
pub trait Federate: Sync + Send + Clone {
pub trait Federate: Sync + Send {
type Error: std::error::Error + std::fmt::Debug;
/// utility method to create dir if not exists
async fn create_dir_if_not_exists(&self, path: &Path) -> Result<(), Self::Error>;
/// utility method to write data
async fn write_util<S: Serialize + Send + Sync>(
&self,
data: &S,
path: &Path,
) -> Result<(), Self::Error>;
/// utility method to remove file/dir
async fn rm_util(&self, path: &Path) -> Result<(), Self::Error>;

View file

@ -87,6 +87,13 @@ impl PccFederate {
}
Ok(path)
}
/// utility method to write data
async fn write_util<S: Serialize + Send + Sync>(&self, data: &S, path: &Path) -> FResult<()> {
let fcontents = serde_yaml::to_string(data)?;
fs::write(path, &fcontents).await?;
Ok(())
}
}
#[async_trait]
@ -101,13 +108,6 @@ impl Federate for PccFederate {
Ok(())
}
/// utility method to write data
async fn write_util<S: Serialize + Send + Sync>(&self, data: &S, path: &Path) -> FResult<()> {
let fcontents = serde_yaml::to_string(data)?;
fs::write(path, &fcontents).await?;
Ok(())
}
/// utility method to remove file/dir
async fn rm_util(&self, path: &Path) -> FResult<()> {
if path.exists() {