diff options
author | Alex Crichton <alex@alexcrichton.com> | 2014-06-28 14:49:04 -0700 |
---|---|---|
committer | Alex Crichton <alex@alexcrichton.com> | 2014-06-28 14:49:04 -0700 |
commit | 0f20aad8238dd02fe0ace0ba587b1a79c5f27704 (patch) | |
tree | 4e7509ed9bb6c3af6dca8117b4b160bedd152a64 /src | |
parent | 6b4f33444ad55b8264cf5ddb70b0bcdff57d42df (diff) | |
download | milf-rs-0f20aad8238dd02fe0ace0ba587b1a79c5f27704.tar.gz milf-rs-0f20aad8238dd02fe0ace0ba587b1a79c5f27704.zip |
Prune more unused fields
Diffstat (limited to 'src')
-rw-r--r-- | src/serialization.rs | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/serialization.rs b/src/serialization.rs index 395e85f..9b1ba01 100644 --- a/src/serialization.rs +++ b/src/serialization.rs @@ -616,7 +616,13 @@ impl serialize::Decoder<DecodeError> for Decoder { Some(Array(ref arr)) => arr.len(), ref found => return Err(self.mismatch("array", found)), }; - f(self, len) + 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) } fn read_seq_elt<T>(&mut self, idx: uint, f: |&mut Decoder| -> Result<T, DecodeError>) @@ -636,7 +642,9 @@ impl serialize::Decoder<DecodeError> for Decoder { Some(Table(ref table)) => table.len(), ref found => return Err(self.mismatch("table", found)), }; - f(self, len) + let ret = try!(f(self, len)); + self.toml.take(); + Ok(ret) } fn read_map_elt_key<T>(&mut self, idx: uint, f: |&mut Decoder| -> Result<T, DecodeError>) @@ -1043,4 +1051,34 @@ mod tests { assert_eq!(d.toml, None); } + + #[test] + fn unused_fields4() { + #[deriving(Encodable, Decodable, PartialEq, Show)] + struct Foo { a: HashMap<String, String> } + + let v = Foo { a: map! { a: "foo".to_string() } }; + let mut d = Decoder::new(Table(map! { + a: Table(map! { + a: String("foo".to_string()) + }) + })); + assert_eq!(v, Decodable::decode(&mut d).unwrap()); + + assert_eq!(d.toml, None); + } + + #[test] + fn unused_fields5() { + #[deriving(Encodable, Decodable, PartialEq, Show)] + struct Foo { a: Vec<String> } + + let v = Foo { a: vec![] }; + let mut d = Decoder::new(Table(map! { + a: Array(vec![]) + })); + assert_eq!(v, Decodable::decode(&mut d).unwrap()); + + assert_eq!(d.toml, None); + } } |