aboutsummaryrefslogtreecommitdiff
path: root/fondant_derive
diff options
context:
space:
mode:
authorMatt Bradbury <[email protected]>2020-04-04 18:19:24 +0100
committerMatt Bradbury <[email protected]>2020-04-04 18:19:24 +0100
commit79f1ea075d0d3ad3514da7120faa1c3c5fd17bfc (patch)
tree79942c90aab8178b742fc167f82dd23ee42d9079 /fondant_derive
parentc6de9f2552b9299f247485c44c1c66d0cd3b2012 (diff)
Hack to make issue #1 sort of work
Diffstat (limited to 'fondant_derive')
-rw-r--r--fondant_derive/src/lib.rs15
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)?;