diff --git a/src/bencode/de.rs b/src/bencode/de.rs index ad2f1fe..3b276ca 100644 --- a/src/bencode/de.rs +++ b/src/bencode/de.rs @@ -226,11 +226,11 @@ impl <'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { visitor.visit_byte_buf(Vec::from(self.parse_byte_string()?)) } - fn deserialize_option(self, _: V) -> Result + fn deserialize_option(self, visitor: V) -> Result where V: Visitor<'de> { - Err(Error::WontImplement) + visitor.visit_some(self) } fn deserialize_unit(self, _: V) -> Result @@ -503,5 +503,17 @@ mod test { ("foo".to_string(), [0x1, 0x2, 0x3]), ("bar".to_string(), [0x19, 0x31, 0x17]), ])); + + #[derive(Deserialize, Debug)] + struct C { + l: Vec, + o: Option, + } + let de: C = from_str("d1:lli23ei17eee").unwrap(); + assert_eq!(de.l, vec![23, 17]); + assert_eq!(de.o, None); + let de: C = from_str("d1:lli23ei17ee1:oi42ee").unwrap(); + assert_eq!(de.l, vec![23, 17]); + assert_eq!(de.o, Some(42)); } }