[bencode/de] Implement options
This commit is contained in:
parent
f90876a324
commit
876fbe15dc
@ -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<V>(self, _: V) -> Result<V::Value>
|
||||
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value>
|
||||
where
|
||||
V: Visitor<'de>
|
||||
{
|
||||
Err(Error::WontImplement)
|
||||
visitor.visit_some(self)
|
||||
}
|
||||
|
||||
fn deserialize_unit<V>(self, _: V) -> Result<V::Value>
|
||||
@ -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<i64>,
|
||||
o: Option<i64>,
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user