From: Ian Jackson Date: Tue, 17 Nov 2020 19:57:36 +0000 (+0000) Subject: wip toml, doex not work, progressing X-Git-Tag: otter-0.2.0~496 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=f27e5290e897c02f665b8b62bbc487925e221a0b;p=otter.git wip toml, doex not work, progressing Signed-off-by: Ian Jackson --- diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 61e3de0c..c5ca7ca6 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -539,7 +539,7 @@ fn read_spec(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))? } diff --git a/src/toml.rs b/src/toml.rs index e5684fe2..8ddc8254 100644 --- a/src/toml.rs +++ b/src/toml.rs @@ -93,9 +93,17 @@ impl<'de> Deserializer<'de> for TomlDe<'de> { fn deserialize_any>(self, visitor: V) -> V::Value { visit(visitor, &self.0)? } + #[throws(Error)] + fn deserialize_option>(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 (s: &str) -> T { let tv : toml::Value = s.parse()?; - eprintln!("TOML FROM STR {:?}", tv); + dbg!(&tv); from_value(&tv)? }