From f1f564dfcd328a1b36e6fefb37e023afebc9d68f Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 12 Apr 2020 12:11:02 +0530 Subject: all loading paths at runtime --- fondant_deps/src/lib.rs | 7 +++---- fondant_derive/src/lib.rs | 7 ++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fondant_deps/src/lib.rs b/fondant_deps/src/lib.rs index 9559b11..82626b7 100644 --- a/fondant_deps/src/lib.rs +++ b/fondant_deps/src/lib.rs @@ -21,7 +21,7 @@ pub mod fondant_exports { } use serde::{de::DeserializeOwned, Serialize}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; #[derive(Debug)] /// Errors that `load` and `store` can result in @@ -44,9 +44,8 @@ pub enum FondantError { /// Derive this trait on a struct to mark it as a 'configuration' struct. pub trait Configure: Serialize + DeserializeOwned + Default { - fn load_file(config_file: &PathBuf) -> Result; + fn load_file>(config_file: P) -> Result; fn load() -> Result; fn store(&self) -> Result<(), FondantError>; - fn store_file(&self, config_file: &PathBuf) -> Result<(), FondantError>; - + fn store_file>(&self, config_file: P) -> Result<(), FondantError>; } diff --git a/fondant_derive/src/lib.rs b/fondant_derive/src/lib.rs index a06df15..2f852dc 100644 --- a/fondant_derive/src/lib.rs +++ b/fondant_derive/src/lib.rs @@ -127,8 +127,8 @@ fn gen_impl(ast: &DeriveInput, cfg_path: ConfigPath) -> TokenStream { Self::load_file(&config_file) } - fn load_file(conf_file: &PathBuf) -> Result<#struct_ident, FondantError> { - #load_paths + fn load_file>(conf_file: P) -> Result<#struct_ident, FondantError> { + #load_paths match File::open(&conf_file) { // Note: conf_file is different than config_file from #load_paths Ok(mut cfg) => { let mut cfg_data = String::new(); @@ -149,13 +149,14 @@ fn gen_impl(ast: &DeriveInput, cfg_path: ConfigPath) -> TokenStream { Err(e) => return Err(FondantError::LoadError), }; } + fn store(&self) -> Result<(), FondantError> { #load_paths &self.store_file(&config_file)?; Ok(()) } - fn store_file(&self, conf_file: &PathBuf) -> Result<(), FondantError> { + fn store_file>(&self, conf_file: P) -> Result<(), FondantError> { #load_paths let mut f = OpenOptions::new() .write(true) -- cgit v1.2.3