aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-06-28 15:00:45 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-06-28 15:00:45 -0700
commit85af1747781985ee359158e9aaa0416f4a4ebf70 (patch)
tree610c6c93a7826e09c6ac12f997d568bf12e71141 /src
parent0f20aad8238dd02fe0ace0ba587b1a79c5f27704 (diff)
downloadmilf-rs-85af1747781985ee359158e9aaa0416f4a4ebf70.tar.gz
milf-rs-85af1747781985ee359158e9aaa0416f4a4ebf70.zip
Always remove Array values from the Decoder
Diffstat (limited to 'src')
-rw-r--r--src/serialization.rs20
1 files changed, 15 insertions, 5 deletions
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<DecodeError> 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<String> }
- 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<Vec<String>> }
+
+ let v = Foo { a: Some(vec![]) };
let mut d = Decoder::new(Table(map! {
a: Array(vec![])
}));