[bencode/de] Implemented any deserialization
This commit is contained in:
parent
7556471090
commit
00e84033b4
@ -81,12 +81,16 @@ impl<'de> Deserializer<'de> {
|
||||
impl <'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
||||
type Error = Error;
|
||||
|
||||
fn deserialize_any<V>(self, _: V) -> Result<V::Value>
|
||||
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
|
||||
where
|
||||
V: Visitor<'de>
|
||||
{
|
||||
println!("i don't get this API!");
|
||||
Err(Error::WontImplement)
|
||||
match self.peek_byte()? as char {
|
||||
'i' => self.deserialize_i64(visitor),
|
||||
'l' => self.deserialize_seq(visitor),
|
||||
'd' => self.deserialize_map(visitor),
|
||||
_ => Err(Error::Syntax),
|
||||
}
|
||||
}
|
||||
|
||||
fn deserialize_bool<V>(self, _: V) -> Result<V::Value>
|
||||
@ -329,12 +333,11 @@ impl <'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
||||
self.deserialize_bytes(visitor)
|
||||
}
|
||||
|
||||
fn deserialize_ignored_any<V>(self, _: V) -> Result<V::Value>
|
||||
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value>
|
||||
where
|
||||
V: Visitor<'de>
|
||||
{
|
||||
println!("i really don't get this API!");
|
||||
Err(Error::WontImplement)
|
||||
self.deserialize_any(visitor)
|
||||
}
|
||||
}
|
||||
|
||||
@ -516,4 +519,14 @@ mod test {
|
||||
assert_eq!(de.l, vec![23, 17]);
|
||||
assert_eq!(de.o, Some(42));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_struct_extra() {
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct A {
|
||||
a: i64,
|
||||
}
|
||||
let de: A = from_str("d1:ai42e1:bi18ee").unwrap();
|
||||
assert_eq!(de.a, 42);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user