chiark / gitweb /
wip toml, doex not work, progressing
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 17 Nov 2020 19:57:36 +0000 (19:57 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 18 Nov 2020 11:30:48 +0000 (11:30 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otter.rs
src/toml.rs

index 61e3de0c2086c732002ed596e734bfc793a820ef..c5ca7ca63f7eab7dcb8e3c8beba7cd194f9211e5 100644 (file)
@@ -539,7 +539,7 @@ fn read_spec<T: DeserializeOwned>(filename: &str, what: &str) -> T {
     let mut f = File::open(filename).context("open")?;
     let mut buf = String::new();
     f.read_to_string(&mut buf).context("read")?;
-    let spec : T = toml::de::from_str(&buf).context("parse")?;
+    let spec : T = otter::toml::from_str(&buf).context("parse")?;
     Ok::<_,AE>(spec)
   })().with_context(|| format!("read {} {:?}", what, filename))?
 }
index e5684fe20d0bafbb71b9a3e074642391ec40bc93..8ddc825457594d59bdc9528aad1d032d158ae53c 100644 (file)
@@ -93,9 +93,17 @@ impl<'de> Deserializer<'de> for TomlDe<'de> {
   fn deserialize_any<V: Visitor<'de>>(self, visitor: V) -> V::Value {
     visit(visitor, &self.0)?
   }
+  #[throws(Error)]
+  fn deserialize_option<V: Visitor<'de>>(self, visitor: V) -> V::Value {
+    // Option only works in structs, where it's represented by an
+    // absence of the key.  When we are called, we are either in a
+    // non-working context, or a context where we've already had
+    // the relevant struct key.
+    visitor.visit_some(self)?
+  }
   forward_to_deserialize_any! {
     bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string
-    bytes byte_buf option unit unit_struct newtype_struct seq tuple
+    bytes byte_buf unit unit_struct newtype_struct seq tuple
     tuple_struct map struct enum identifier ignored_any
   }
 }
@@ -110,6 +118,6 @@ pub fn from_value<'de, T: Deserialize<'de>> (tv: &'de toml::Value) -> T
 pub fn from_str<T: DeserializeOwned> (s: &str) -> T
 {
   let tv : toml::Value = s.parse()?;
-  eprintln!("TOML FROM STR {:?}", tv);
+  dbg!(&tv);
   from_value(&tv)?
 }