feat: mv write_util out of Federate trait for allowing creation of trait objs
This commit is contained in:
parent
882fde7d20
commit
519855a7c3
2 changed files with 8 additions and 16 deletions
|
@ -19,7 +19,6 @@ use std::path::Path;
|
||||||
use std::result::Result;
|
use std::result::Result;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
use db_core::prelude::*;
|
use db_core::prelude::*;
|
||||||
|
|
||||||
|
@ -27,19 +26,12 @@ use db_core::prelude::*;
|
||||||
pub mod tests;
|
pub mod tests;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Federate: Sync + Send + Clone {
|
pub trait Federate: Sync + Send {
|
||||||
type Error: std::error::Error + std::fmt::Debug;
|
type Error: std::error::Error + std::fmt::Debug;
|
||||||
|
|
||||||
/// utility method to create dir if not exists
|
/// utility method to create dir if not exists
|
||||||
async fn create_dir_if_not_exists(&self, path: &Path) -> Result<(), Self::Error>;
|
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
|
/// utility method to remove file/dir
|
||||||
async fn rm_util(&self, path: &Path) -> Result<(), Self::Error>;
|
async fn rm_util(&self, path: &Path) -> Result<(), Self::Error>;
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,13 @@ impl PccFederate {
|
||||||
}
|
}
|
||||||
Ok(path)
|
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]
|
#[async_trait]
|
||||||
|
@ -101,13 +108,6 @@ impl Federate for PccFederate {
|
||||||
Ok(())
|
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
|
/// utility method to remove file/dir
|
||||||
async fn rm_util(&self, path: &Path) -> FResult<()> {
|
async fn rm_util(&self, path: &Path) -> FResult<()> {
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
|
|
Loading…
Reference in a new issue