diff options
author | Alex Crichton <alex@alexcrichton.com> | 2014-06-28 14:42:30 -0700 |
---|---|---|
committer | Alex Crichton <alex@alexcrichton.com> | 2014-06-28 14:42:30 -0700 |
commit | 6b4f33444ad55b8264cf5ddb70b0bcdff57d42df (patch) | |
tree | be2c3f033705c7bddc9b61d0dd699c83e2eb3e9f | |
parent | 9c1806283c5a631e44d1ecca016e217f889319ef (diff) | |
download | milf-rs-6b4f33444ad55b8264cf5ddb70b0bcdff57d42df.tar.gz milf-rs-6b4f33444ad55b8264cf5ddb70b0bcdff57d42df.zip |
Don't leave empty tables lying around
-rw-r--r-- | src/serialization.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/serialization.rs b/src/serialization.rs index 26fc7ba..395e85f 100644 --- a/src/serialization.rs +++ b/src/serialization.rs @@ -536,7 +536,15 @@ impl serialize::Decoder<DecodeError> for Decoder { -> Result<T, DecodeError> { match self.toml { - Some(Table(..)) => f(self), + Some(Table(..)) => { + let ret = try!(f(self)); + match self.toml { + Some(Table(ref t)) if t.len() == 0 => {} + _ => return Ok(ret) + } + self.toml.take(); + Ok(ret) + } ref found => Err(self.mismatch("table", found)), } } @@ -1017,4 +1025,22 @@ mod tests { }) }))); } + + #[test] + fn unused_fields3() { + #[deriving(Encodable, Decodable, PartialEq, Show)] + struct Foo { a: Bar } + #[deriving(Encodable, Decodable, PartialEq, Show)] + struct Bar { a: int } + + let v = Foo { a: Bar { a: 2 } }; + let mut d = Decoder::new(Table(map! { + a: Table(map! { + a: Integer(2) + }) + })); + assert_eq!(v, Decodable::decode(&mut d).unwrap()); + + assert_eq!(d.toml, None); + } } |