diff rust/src/config.rs @ 599:f71cf1ad745f rust

updated toml serde works OK
author Matt Johnston <matt@ucc.asn.au>
date Tue, 07 Feb 2017 22:35:29 +0800
parents d4fbfb5c46ff
children 9c76f3cf01ea
line wrap: on
line diff
--- a/rust/src/config.rs	Tue Feb 07 21:56:58 2017 +0800
+++ b/rust/src/config.rs	Tue Feb 07 22:35:29 2017 +0800
@@ -65,14 +65,23 @@
     }
 
     pub fn to_toml_string(&self) -> String {
-        let mut e = toml::Encoder::new();
-        self.serialize(&mut e).unwrap();
-        toml::Value::Table(e.toml).to_string()
+        toml::to_string(self).unwrap()
     }
 
 
     pub fn merge(&self, conf: &str) -> Result<Self, String>{
+        println!("config {}", conf);
+        let mut new_toml = try!(toml::from_str(conf).map_err(|e| e.to_string()));
+        let mut ex_val = toml::Value::try_from(self).unwrap();
+        let mut ex_toml = ex_val.as_table_mut().unwrap();
+        ex_toml.append(&mut new_toml);
+        let ret: Self = toml::Value::Table(ex_toml.clone()).try_into().unwrap();
+        return Ok(ret)
+
+
+        /*
         let mut p = toml::Parser::new(&conf);
+        let p =
         p.parse()
             .ok_or_else(|| {
                 format!("toml parsing failed: {:?}", p.errors)
@@ -85,6 +94,7 @@
                 let mut dec = toml::Decoder::new(toml::Value::Table(ex_toml));
                 Self::deserialize(&mut dec).unwrap() // could this go wrong?
             })
+            */
     }
 
     pub fn merge_file(&self, filename: &str) -> Result<Self, String>{