From 519855a7c34b334dd694e3690aa38487cf5c1b2a Mon Sep 17 00:00:00 2001 From: realaravinth Date: Tue, 17 May 2022 20:11:35 +0530 Subject: [PATCH] feat: mv write_util out of Federate trait for allowing creation of trait objs --- federate/federate-core/src/lib.rs | 10 +--------- federate/publiccodeyml/src/lib.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/federate/federate-core/src/lib.rs b/federate/federate-core/src/lib.rs index 67d8f2d..04da48a 100644 --- a/federate/federate-core/src/lib.rs +++ b/federate/federate-core/src/lib.rs @@ -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( - &self, - data: &S, - path: &Path, - ) -> Result<(), Self::Error>; - /// utility method to remove file/dir async fn rm_util(&self, path: &Path) -> Result<(), Self::Error>; diff --git a/federate/publiccodeyml/src/lib.rs b/federate/publiccodeyml/src/lib.rs index 86837d5..9d63aa9 100644 --- a/federate/publiccodeyml/src/lib.rs +++ b/federate/publiccodeyml/src/lib.rs @@ -87,6 +87,13 @@ impl PccFederate { } Ok(path) } + + /// utility method to write data + async fn write_util(&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(&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() {