From 79f1ea075d0d3ad3514da7120faa1c3c5fd17bfc Mon Sep 17 00:00:00 2001 From: Matt Bradbury Date: Sat, 4 Apr 2020 12:19:24 -0500 Subject: Hack to make issue #1 sort of work --- fondant_derive/src/lib.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'fondant_derive') diff --git a/fondant_derive/src/lib.rs b/fondant_derive/src/lib.rs index 62106c4..a06df15 100644 --- a/fondant_derive/src/lib.rs +++ b/fondant_derive/src/lib.rs @@ -124,7 +124,12 @@ fn gen_impl(ast: &DeriveInput, cfg_path: ConfigPath) -> TokenStream { impl Configure for #struct_ident { fn load() -> Result<#struct_ident, FondantError> { #load_paths - match File::open(&config_file) { + Self::load_file(&config_file) + } + + fn load_file(conf_file: &PathBuf) -> 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(); cfg.read_to_string(&mut cfg_data).unwrap(); @@ -145,12 +150,18 @@ fn gen_impl(ast: &DeriveInput, cfg_path: ConfigPath) -> TokenStream { }; } fn store(&self) -> Result<(), FondantError> { + #load_paths + &self.store_file(&config_file)?; + Ok(()) + } + + fn store_file(&self, conf_file: &PathBuf) -> Result<(), FondantError> { #load_paths let mut f = OpenOptions::new() .write(true) .create(true) .truncate(true) - .open(config_file) + .open(conf_file) // Note: conf_file is different than config_file from #load_paths .map_err(|_| FondantError::FileOpenError)?; let s = #ser::#ser_fn(self).map_err(|_| FondantError::ConfigParseError)?; -- cgit v1.2.3