diff options
Diffstat (limited to 'src/encoder')
-rw-r--r-- | src/encoder/mod.rs | 8 | ||||
-rw-r--r-- | src/encoder/rustc_serialize.rs | 11 |
2 files changed, 8 insertions, 11 deletions
diff --git a/src/encoder/mod.rs b/src/encoder/mod.rs index ea8ef6a..21185f4 100644 --- a/src/encoder/mod.rs +++ b/src/encoder/mod.rs @@ -31,7 +31,7 @@ use {Value, Table}; /// let mut e = Encoder::new(); /// my_struct.encode(&mut e).unwrap(); /// -/// assert_eq!(e.toml.0.get(&"foo".to_string()), Some(&Value::Integer(4))) +/// assert_eq!(e.toml.get(&"foo".to_string()), Some(&Value::Integer(4))) /// # } /// ``` pub struct Encoder { @@ -73,12 +73,12 @@ enum State { impl Encoder { /// Constructs a new encoder which will emit to the given output stream. pub fn new() -> Encoder { - Encoder { state: State::Start, toml: Table(BTreeMap::new(), false) } + Encoder { state: State::Start, toml: BTreeMap::new() } } fn emit_value(&mut self, v: Value) -> Result<(), Error> { match mem::replace(&mut self.state, State::Start) { - State::NextKey(key) => { self.toml.0.insert(key, v); Ok(()) } + State::NextKey(key) => { self.toml.insert(key, v); Ok(()) } State::NextArray(mut vec) => { // TODO: validate types vec.push(v); @@ -122,7 +122,7 @@ impl Encoder { State::NextKey(key) => { let mut nested = Encoder::new(); try!(f(&mut nested)); - self.toml.0.insert(key, Value::Table(nested.toml)); + self.toml.insert(key, Value::Table(nested.toml)); Ok(()) } State::NextArray(mut arr) => { diff --git a/src/encoder/rustc_serialize.rs b/src/encoder/rustc_serialize.rs index 830eb5e..ab5e90f 100644 --- a/src/encoder/rustc_serialize.rs +++ b/src/encoder/rustc_serialize.rs @@ -193,8 +193,8 @@ impl rustc_serialize::Encodable for Value { }) } Value::Table(ref t) => { - e.emit_map(t.0.len(), |e| { - for (i, (key, value)) in t.0.iter().enumerate() { + e.emit_map(t.len(), |e| { + for (i, (key, value)) in t.iter().enumerate() { try!(e.emit_map_elt_key(i, |e| e.emit_str(key))); try!(e.emit_map_elt_val(i, |e| value.encode(e))); } @@ -212,7 +212,6 @@ mod tests { use {Encoder, Decoder, DecodeError}; use Value; - use Table as TomlTable; use Value::{Table, Integer, Array, Float}; macro_rules! encode( ($t:expr) => ({ @@ -229,7 +228,7 @@ mod tests { macro_rules! map( ($($k:ident, $v:expr),*) => ({ let mut _m = BTreeMap::new(); $(_m.insert(stringify!($k).to_string(), $v);)* - TomlTable::new(_m) + _m }) ); #[test] @@ -578,9 +577,7 @@ mod tests { #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)] struct Foo { a: BTreeMap<String, String> } - let mut v = Foo { a: BTreeMap::new() }; - v.a.insert("a".to_string(), "foo".to_string()); - + let v = Foo { a: map! { a, "foo".to_string() } }; let mut d = Decoder::new(Table(map! { a, Table(map! { a, Value::String("foo".to_string()) |