diff options
Diffstat (limited to 'fondant_derive/src')
-rw-r--r-- | fondant_derive/src/lib.rs | 15 |
1 files changed, 13 insertions, 2 deletions
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 { | |||
124 | impl Configure for #struct_ident { | 124 | impl Configure for #struct_ident { |
125 | fn load() -> Result<#struct_ident, FondantError> { | 125 | fn load() -> Result<#struct_ident, FondantError> { |
126 | #load_paths | 126 | #load_paths |
127 | match File::open(&config_file) { | 127 | Self::load_file(&config_file) |
128 | } | ||
129 | |||
130 | fn load_file(conf_file: &PathBuf) -> Result<#struct_ident, FondantError> { | ||
131 | #load_paths | ||
132 | match File::open(&conf_file) { // Note: conf_file is different than config_file from #load_paths | ||
128 | Ok(mut cfg) => { | 133 | Ok(mut cfg) => { |
129 | let mut cfg_data = String::new(); | 134 | let mut cfg_data = String::new(); |
130 | cfg.read_to_string(&mut cfg_data).unwrap(); | 135 | cfg.read_to_string(&mut cfg_data).unwrap(); |
@@ -146,11 +151,17 @@ fn gen_impl(ast: &DeriveInput, cfg_path: ConfigPath) -> TokenStream { | |||
146 | } | 151 | } |
147 | fn store(&self) -> Result<(), FondantError> { | 152 | fn store(&self) -> Result<(), FondantError> { |
148 | #load_paths | 153 | #load_paths |
154 | &self.store_file(&config_file)?; | ||
155 | Ok(()) | ||
156 | } | ||
157 | |||
158 | fn store_file(&self, conf_file: &PathBuf) -> Result<(), FondantError> { | ||
159 | #load_paths | ||
149 | let mut f = OpenOptions::new() | 160 | let mut f = OpenOptions::new() |
150 | .write(true) | 161 | .write(true) |
151 | .create(true) | 162 | .create(true) |
152 | .truncate(true) | 163 | .truncate(true) |
153 | .open(config_file) | 164 | .open(conf_file) // Note: conf_file is different than config_file from #load_paths |
154 | .map_err(|_| FondantError::FileOpenError)?; | 165 | .map_err(|_| FondantError::FileOpenError)?; |
155 | 166 | ||
156 | let s = #ser::#ser_fn(self).map_err(|_| FondantError::ConfigParseError)?; | 167 | let s = #ser::#ser_fn(self).map_err(|_| FondantError::ConfigParseError)?; |