From 85af1747781985ee359158e9aaa0416f4a4ebf70 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 28 Jun 2014 15:00:45 -0700 Subject: Always remove Array values from the Decoder --- src/serialization.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/serialization.rs b/src/serialization.rs index 9b1ba01..a7c6f2b 100644 --- a/src/serialization.rs +++ b/src/serialization.rs @@ -617,10 +617,6 @@ impl serialize::Decoder for Decoder { ref found => return Err(self.mismatch("array", found)), }; let ret = try!(f(self, len)); - match self.toml { - Some(Array(ref arr)) if arr.len() == 0 => {} - _ => return Ok(ret) - } self.toml.take(); Ok(ret) } @@ -1073,7 +1069,21 @@ mod tests { #[deriving(Encodable, Decodable, PartialEq, Show)] struct Foo { a: Vec } - let v = Foo { a: vec![] }; + let v = Foo { a: vec!["a".to_string()] }; + let mut d = Decoder::new(Table(map! { + a: Array(vec![String("a".to_string())]) + })); + assert_eq!(v, Decodable::decode(&mut d).unwrap()); + + assert_eq!(d.toml, None); + } + + #[test] + fn unused_fields6() { + #[deriving(Encodable, Decodable, PartialEq, Show)] + struct Foo { a: Option> } + + let v = Foo { a: Some(vec![]) }; let mut d = Decoder::new(Table(map! { a: Array(vec![]) })); -- cgit v1.2.3