From d4319caa2073a8f7e14f4479d7f4d374357f890a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 9 Jan 2015 11:48:06 -0800 Subject: Bump to 0.1.11 --- src/lib.rs | 7 ++- src/parser.rs | 36 +++++++------- src/serialization.rs | 134 +++++++++++++++++++++++++++------------------------ src/show.rs | 47 +++++++----------- 4 files changed, 111 insertions(+), 113 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 4d714f0..a046189 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,9 +37,8 @@ //! #![deny(missing_docs)] -#![allow(staged_experimental)] -#![allow(staged_unstable)] #![cfg_attr(test, deny(warnings))] +#![allow(unstable)] extern crate "rustc-serialize" as rustc_serialize; @@ -159,7 +158,7 @@ impl Value { /// Note: arrays have zero-based indexes. /// /// ``` - /// # #![allow(staged_unstable)] + /// # #![allow(unstable)] /// let toml = r#" /// [test] /// foo = "bar" @@ -192,7 +191,7 @@ impl Value { } }, &Value::Array(ref v) => { - match key.parse::() { + match key.parse::() { Some(idx) if idx < v.len() => cur_value = &v[idx], _ => return None } diff --git a/src/parser.rs b/src/parser.rs index 6df4699..721c83c 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -30,9 +30,9 @@ pub struct Parser<'a> { #[derive(Show)] pub struct ParserError { /// The low byte at which this error is pointing at. - pub lo: uint, + pub lo: usize, /// One byte beyond the last character at which this error is pointing at. - pub hi: uint, + pub hi: usize, /// A human-readable description explaining what the error is. pub desc: String, } @@ -69,7 +69,7 @@ impl<'a> Parser<'a> { /// Converts a byte offset from an error message to a (line, column) pair /// /// All indexes are 0-based. - pub fn to_linecol(&self, offset: uint) -> (uint, uint) { + pub fn to_linecol(&self, offset: usize) -> (usize, usize) { let mut cur = 0; for (i, line) in self.input.lines().enumerate() { if cur + line.len() > offset { @@ -80,7 +80,7 @@ impl<'a> Parser<'a> { return (self.input.lines().count(), 0) } - fn next_pos(&self) -> uint { + fn next_pos(&self) -> usize { self.cur.clone().next().map(|p| p.0).unwrap_or(self.input.len()) } @@ -271,7 +271,7 @@ impl<'a> Parser<'a> { } // Parses a single or multi-line string - fn string(&mut self, start: uint) -> Option { + fn string(&mut self, start: usize) -> Option { if !self.expect('"') { return None } let mut multiline = false; let mut ret = String::new(); @@ -331,7 +331,7 @@ impl<'a> Parser<'a> { return Some(Value::String(ret)); - fn escape(me: &mut Parser, pos: uint, multiline: bool) -> Option { + fn escape(me: &mut Parser, pos: usize, multiline: bool) -> Option { match me.cur.next() { Some((_, 'b')) => Some('\u{8}'), Some((_, 't')) => Some('\u{9}'), @@ -417,7 +417,7 @@ impl<'a> Parser<'a> { } } - fn literal_string(&mut self, start: uint) -> Option { + fn literal_string(&mut self, start: usize) -> Option { if !self.expect('\'') { return None } let mut multiline = false; let mut ret = String::new(); @@ -453,7 +453,7 @@ impl<'a> Parser<'a> { return Some(Value::String(ret)); } - fn number_or_datetime(&mut self, start: uint) -> Option { + fn number_or_datetime(&mut self, start: usize) -> Option { let negative = self.eat('-'); let mut is_float = false; loop { @@ -488,15 +488,15 @@ impl<'a> Parser<'a> { return ret; } - fn boolean(&mut self, start: uint) -> Option { + fn boolean(&mut self, start: usize) -> Option { let rest = self.input.slice_from(start); if rest.starts_with("true") { - for _ in range(0u, 4u) { + for _ in 0..4 { self.cur.next(); } Some(Boolean(true)) } else if rest.starts_with("false") { - for _ in range(0u, 5u) { + for _ in 0..5 { self.cur.next(); } Some(Boolean(false)) @@ -512,9 +512,9 @@ impl<'a> Parser<'a> { } } - fn datetime(&mut self, start: uint, end_so_far: uint) -> Option { + fn datetime(&mut self, start: usize, end_so_far: usize) -> Option { let mut date = self.input.slice(start, end_so_far).to_string(); - for _ in range(0u, 15u) { + for _ in 0..15 { match self.cur.next() { Some((_, ch)) => date.push(ch), None => { @@ -561,7 +561,7 @@ impl<'a> Parser<'a> { } } - fn array(&mut self, _start: uint) -> Option { + fn array(&mut self, _start: usize) -> Option { if !self.expect('[') { return None } let mut ret = Vec::new(); fn consume(me: &mut Parser) { @@ -612,7 +612,7 @@ impl<'a> Parser<'a> { } fn insert(&mut self, into: &mut TomlTable, key: String, value: Value, - key_lo: uint) { + key_lo: usize) { if into.contains_key(&key) { self.errors.push(ParserError { lo: key_lo, @@ -625,7 +625,7 @@ impl<'a> Parser<'a> { } fn recurse<'b>(&mut self, mut cur: &'b mut TomlTable, orig_key: &'b str, - key_lo: uint) -> Option<(&'b mut TomlTable, &'b str)> { + key_lo: usize) -> Option<(&'b mut TomlTable, &'b str)> { if orig_key.starts_with(".") || orig_key.ends_with(".") || orig_key.contains("..") { self.errors.push(ParserError { @@ -687,7 +687,7 @@ impl<'a> Parser<'a> { } fn insert_table(&mut self, into: &mut TomlTable, key: String, value: TomlTable, - key_lo: uint) { + key_lo: usize) { let (into, key) = match self.recurse(into, key.as_slice(), key_lo) { Some(pair) => pair, None => return, @@ -730,7 +730,7 @@ impl<'a> Parser<'a> { } fn insert_array(&mut self, into: &mut TomlTable, key: String, value: Value, - key_lo: uint) { + key_lo: usize) { let (into, key) = match self.recurse(into, key.as_slice(), key_lo) { Some(pair) => pair, None => return, diff --git a/src/serialization.rs b/src/serialization.rs index 4f0fd19..767c160 100644 --- a/src/serialization.rs +++ b/src/serialization.rs @@ -23,9 +23,7 @@ use self::DecodeErrorKind::{ExpectedMapElement, NoEnumVariants, NilTooLong}; /// # Example /// /// ``` -/// # #![feature(old_orphan_check)] -/// # #![allow(staged_unstable)] -/// # #![allow(staged_experimental)] +/// # #![allow(unstable)] /// extern crate "rustc-serialize" as rustc_serialize; /// extern crate toml; /// @@ -92,7 +90,7 @@ pub struct DecodeError { } /// Enumeration of possible errors which can occur while decoding a structure. -#[derive(PartialEq)] +#[derive(PartialEq, Show)] pub enum DecodeErrorKind { /// An error flagged by the application, e.g. value out of range ApplicationError(String), @@ -101,9 +99,9 @@ pub enum DecodeErrorKind { /// A field was found, but it had the wrong type. ExpectedType(/* expected */ &'static str, /* found */ &'static str), /// The nth map key was expected, but none was found. - ExpectedMapKey(uint), + ExpectedMapKey(usize), /// The nth map element was expected, but none was found. - ExpectedMapElement(uint), + ExpectedMapElement(usize), /// An enum decoding was requested, but no variants were supplied NoEnumVariants, /// The unit type was being decoded, but a non-zero length string was found @@ -166,7 +164,7 @@ impl rustc_serialize::Encoder for Encoder { type Error = Error; fn emit_nil(&mut self) -> Result<(), Error> { Ok(()) } - fn emit_usize(&mut self, v: uint) -> Result<(), Error> { + fn emit_usize(&mut self, v: usize) -> Result<(), Error> { self.emit_i64(v as i64) } fn emit_u8(&mut self, v: u8) -> Result<(), Error> { @@ -181,7 +179,7 @@ impl rustc_serialize::Encoder for Encoder { fn emit_u64(&mut self, v: u64) -> Result<(), Error> { self.emit_i64(v as i64) } - fn emit_isize(&mut self, v: int) -> Result<(), Error> { + fn emit_isize(&mut self, v: isize) -> Result<(), Error> { self.emit_i64(v as i64) } fn emit_i8(&mut self, v: i8) -> Result<(), Error> { @@ -215,20 +213,20 @@ impl rustc_serialize::Encoder for Encoder { { f(self) } - fn emit_enum_variant(&mut self, _v_name: &str, _v_id: uint, _len: uint, f: F) - -> Result<(), Error> + fn emit_enum_variant(&mut self, _v_name: &str, _v_id: usize, + _len: usize, f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { f(self) } - fn emit_enum_variant_arg(&mut self, _a_idx: uint, f: F) + fn emit_enum_variant_arg(&mut self, _a_idx: usize, f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { f(self) } - fn emit_enum_struct_variant(&mut self, _v_name: &str, _v_id: uint, - _len: uint, + fn emit_enum_struct_variant(&mut self, _v_name: &str, _v_id: usize, + _len: usize, _f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> @@ -237,14 +235,14 @@ impl rustc_serialize::Encoder for Encoder { } fn emit_enum_struct_variant_field(&mut self, _f_name: &str, - _f_idx: uint, + _f_idx: usize, _f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { panic!() } - fn emit_struct(&mut self, _name: &str, _len: uint, f: F) + fn emit_struct(&mut self, _name: &str, _len: usize, f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { @@ -266,7 +264,7 @@ impl rustc_serialize::Encoder for Encoder { NextMapKey => Err(InvalidMapKeyLocation), } } - fn emit_struct_field(&mut self, f_name: &str, _f_idx: uint, f: F) + fn emit_struct_field(&mut self, f_name: &str, _f_idx: usize, f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { @@ -278,25 +276,25 @@ impl rustc_serialize::Encoder for Encoder { self.state = old; Ok(()) } - fn emit_tuple(&mut self, len: uint, f: F) + fn emit_tuple(&mut self, len: usize, f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { self.emit_seq(len, f) } - fn emit_tuple_arg(&mut self, idx: uint, f: F) + fn emit_tuple_arg(&mut self, idx: usize, f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { self.emit_seq_elt(idx, f) } - fn emit_tuple_struct(&mut self, _name: &str, _len: uint, _f: F) + fn emit_tuple_struct(&mut self, _name: &str, _len: usize, _f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { unimplemented!() } - fn emit_tuple_struct_arg(&mut self, _f_idx: uint, _f: F) + fn emit_tuple_struct_arg(&mut self, _f_idx: usize, _f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { @@ -322,7 +320,7 @@ impl rustc_serialize::Encoder for Encoder { { f(self) } - fn emit_seq(&mut self, _len: uint, f: F) + fn emit_seq(&mut self, _len: usize, f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { @@ -333,19 +331,19 @@ impl rustc_serialize::Encoder for Encoder { _ => unreachable!(), } } - fn emit_seq_elt(&mut self, _idx: uint, f: F) + fn emit_seq_elt(&mut self, _idx: usize, f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { f(self) } - fn emit_map(&mut self, len: uint, f: F) + fn emit_map(&mut self, len: usize, f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { self.emit_struct("foo", len, f) } - fn emit_map_elt_key(&mut self, _idx: uint, mut f: F) + fn emit_map_elt_key(&mut self, _idx: usize, mut f: F) -> Result<(), Error> where F: FnMut(&mut Encoder) -> Result<(), Error> { @@ -359,7 +357,7 @@ impl rustc_serialize::Encoder for Encoder { _ => Err(InvalidMapKeyLocation), } } - fn emit_map_elt_val(&mut self, _idx: uint, f: F) + fn emit_map_elt_val(&mut self, _idx: usize, f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { @@ -441,8 +439,8 @@ impl rustc_serialize::Decoder for Decoder { self.toml.take(); Ok(()) } - fn read_usize(&mut self) -> Result { - self.read_i64().map(|i| i as uint) + fn read_usize(&mut self) -> Result { + self.read_i64().map(|i| i as usize) } fn read_u64(&mut self) -> Result { self.read_i64().map(|i| i as u64) @@ -456,8 +454,8 @@ impl rustc_serialize::Decoder for Decoder { fn read_u8(&mut self) -> Result { self.read_i64().map(|i| i as u8) } - fn read_isize(&mut self) -> Result { - self.read_i64().map(|i| i as int) + fn read_isize(&mut self) -> Result { + self.read_i64().map(|i| i as isize) } fn read_i64(&mut self) -> Result { match self.toml { @@ -519,7 +517,7 @@ impl rustc_serialize::Decoder for Decoder { fn read_enum_variant(&mut self, names: &[&str], mut f: F) -> Result - where F: FnMut(&mut Decoder, uint) -> Result + where F: FnMut(&mut Decoder, usize) -> Result { let mut first_error = None; for i in range(0, names.len()) { @@ -535,7 +533,7 @@ impl rustc_serialize::Decoder for Decoder { } Err(first_error.unwrap_or_else(|| self.err(NoEnumVariants))) } - fn read_enum_variant_arg(&mut self, _a_idx: uint, f: F) + fn read_enum_variant_arg(&mut self, _a_idx: usize, f: F) -> Result where F: FnOnce(&mut Decoder) -> Result { @@ -544,13 +542,13 @@ impl rustc_serialize::Decoder for Decoder { fn read_enum_struct_variant(&mut self, _names: &[&str], _f: F) -> Result - where F: FnMut(&mut Decoder, uint) -> Result + where F: FnMut(&mut Decoder, usize) -> Result { panic!() } fn read_enum_struct_variant_field(&mut self, _f_name: &str, - _f_idx: uint, + _f_idx: usize, _f: F) -> Result where F: FnOnce(&mut Decoder) -> Result @@ -558,7 +556,7 @@ impl rustc_serialize::Decoder for Decoder { panic!() } - fn read_struct(&mut self, _s_name: &str, _len: uint, f: F) + fn read_struct(&mut self, _s_name: &str, _len: usize, f: F) -> Result where F: FnOnce(&mut Decoder) -> Result { @@ -575,7 +573,7 @@ impl rustc_serialize::Decoder for Decoder { ref found => Err(self.mismatch("table", found)), } } - fn read_struct_field(&mut self, f_name: &str, _f_idx: uint, f: F) + fn read_struct_field(&mut self, f_name: &str, _f_idx: usize, f: F) -> Result where F: FnOnce(&mut Decoder) -> Result { @@ -599,7 +597,7 @@ impl rustc_serialize::Decoder for Decoder { Ok(ret) } - fn read_tuple(&mut self, tuple_len: uint, f: F) + fn read_tuple(&mut self, tuple_len: usize, f: F) -> Result where F: FnOnce(&mut Decoder) -> Result { @@ -610,20 +608,20 @@ impl rustc_serialize::Decoder for Decoder { f(d) }) } - fn read_tuple_arg(&mut self, a_idx: uint, f: F) + fn read_tuple_arg(&mut self, a_idx: usize, f: F) -> Result where F: FnOnce(&mut Decoder) -> Result { self.read_seq_elt(a_idx, f) } - fn read_tuple_struct(&mut self, _s_name: &str, _len: uint, _f: F) + fn read_tuple_struct(&mut self, _s_name: &str, _len: usize, _f: F) -> Result where F: FnOnce(&mut Decoder) -> Result { panic!() } - fn read_tuple_struct_arg(&mut self, _a_idx: uint, _f: F) + fn read_tuple_struct_arg(&mut self, _a_idx: usize, _f: F) -> Result where F: FnOnce(&mut Decoder) -> Result { @@ -643,7 +641,7 @@ impl rustc_serialize::Decoder for Decoder { fn read_seq(&mut self, f: F) -> Result - where F: FnOnce(&mut Decoder,uint) -> Result + where F: FnOnce(&mut Decoder, usize) -> Result { let len = match self.toml { Some(Array(ref arr)) => arr.len(), @@ -661,7 +659,7 @@ impl rustc_serialize::Decoder for Decoder { self.toml.take(); Ok(ret) } - fn read_seq_elt(&mut self, idx: uint, f: F) + fn read_seq_elt(&mut self, idx: usize, f: F) -> Result where F: FnOnce(&mut Decoder) -> Result { @@ -683,7 +681,7 @@ impl rustc_serialize::Decoder for Decoder { fn read_map(&mut self, f: F) -> Result - where F: FnOnce(&mut Decoder, uint) -> Result + where F: FnOnce(&mut Decoder, usize) -> Result { let len = match self.toml { Some(Table(ref table)) => table.len(), @@ -693,7 +691,7 @@ impl rustc_serialize::Decoder for Decoder { self.toml.take(); Ok(ret) } - fn read_map_elt_key(&mut self, idx: uint, f: F) + fn read_map_elt_key(&mut self, idx: usize, f: F) -> Result where F: FnOnce(&mut Decoder) -> Result { @@ -710,7 +708,7 @@ impl rustc_serialize::Decoder for Decoder { ref found => Err(self.mismatch("table", found)), } } - fn read_map_elt_val(&mut self, idx: uint, f: F) + fn read_map_elt_val(&mut self, idx: usize, f: F) -> Result where F: FnOnce(&mut Decoder) -> Result { @@ -737,6 +735,12 @@ impl rustc_serialize::Decoder for Decoder { } impl fmt::Show for DecodeError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::String::fmt(self, f) + } +} + +impl fmt::String for DecodeError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(match self.kind { ApplicationError(ref err) => { @@ -799,6 +803,12 @@ impl StdError for DecodeError { } impl fmt::Show for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::String::fmt(self, f) + } +} + +impl fmt::String for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { NeedsKey => write!(f, "need a key to encode"), @@ -845,7 +855,7 @@ mod tests { #[test] fn smoke() { #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] - struct Foo { a: int } + struct Foo { a: isize } let v = Foo { a: 2 }; assert_eq!(encode!(v), map! { a, Integer(2) }); @@ -855,7 +865,7 @@ mod tests { #[test] fn smoke_hyphen() { #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] - struct Foo { a_b: int } + struct Foo { a_b: isize } let v = Foo { a_b: 2 }; assert_eq!(encode!(v), map! { a_b, Integer(2) }); @@ -869,7 +879,7 @@ mod tests { #[test] fn nested() { #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] - struct Foo { a: int, b: Bar } + struct Foo { a: isize, b: Bar } #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] struct Bar { a: String } @@ -887,10 +897,10 @@ mod tests { #[test] fn application_decode_error() { #[derive(PartialEq, Show)] - struct Range10(uint); + struct Range10(usize); impl Decodable for Range10 { fn decode(d: &mut D) -> Result { - let x: uint = try!(Decodable::decode(d)); + let x: usize = try!(Decodable::decode(d)); if x > 10 { Err(d.error("Value out of range!")) } else { @@ -899,7 +909,7 @@ mod tests { } } let mut d_good = Decoder::new(Integer(5)); - let mut d_bad1 = Decoder::new(Value::String("not an int".to_string())); + let mut d_bad1 = Decoder::new(Value::String("not an isize".to_string())); let mut d_bad2 = Decoder::new(Integer(11)); assert_eq!(Ok(Range10(5)), Decodable::decode(&mut d_good)); @@ -913,7 +923,7 @@ mod tests { #[test] fn array() { #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] - struct Foo { a: Vec } + struct Foo { a: Vec } let v = Foo { a: vec![1, 2, 3, 4] }; assert_eq!(encode!(v), @@ -931,7 +941,7 @@ mod tests { #[test] fn tuple() { #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] - struct Foo { a: (int, int, int, int) } + struct Foo { a: (isize, isize, isize, isize) } let v = Foo { a: (1, 2, 3, 4) }; assert_eq!(encode!(v), @@ -986,7 +996,7 @@ mod tests { fn hashmap() { #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] struct Foo { - map: BTreeMap, + map: BTreeMap, set: HashSet, } @@ -1018,7 +1028,7 @@ mod tests { #[test] fn tuple_struct() { #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] - struct Foo(int, String, f64); + struct Foo(isize, String, f64); let v = Foo(1, "foo".to_string(), 4.5); assert_eq!( @@ -1037,7 +1047,7 @@ mod tests { #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] struct Foo { a: Vec, } #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] - struct Bar { a: int } + struct Bar { a: isize } let v = Foo { a: vec![Bar { a: 1 }, Bar { a: 2 }] }; assert_eq!( @@ -1055,7 +1065,7 @@ mod tests { #[test] fn type_errors() { #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] - struct Foo { bar: int } + struct Foo { bar: isize } let mut d = Decoder::new(Table(map! { bar, Float(1.0) @@ -1074,7 +1084,7 @@ mod tests { #[test] fn missing_errors() { #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] - struct Foo { bar: int } + struct Foo { bar: isize } let mut d = Decoder::new(Table(map! { })); @@ -1094,7 +1104,7 @@ mod tests { struct Foo { a: E } #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] enum E { - Bar(int), + Bar(isize), Baz(f64), Last(Foo2), } @@ -1128,7 +1138,7 @@ mod tests { #[test] fn unused_fields() { #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] - struct Foo { a: int } + struct Foo { a: isize } let v = Foo { a: 2 }; let mut d = Decoder::new(Table(map! { @@ -1147,7 +1157,7 @@ mod tests { #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] struct Foo { a: Bar } #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] - struct Bar { a: int } + struct Bar { a: isize } let v = Foo { a: Bar { a: 2 } }; let mut d = Decoder::new(Table(map! { @@ -1170,7 +1180,7 @@ mod tests { #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] struct Foo { a: Bar } #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] - struct Bar { a: int } + struct Bar { a: isize } let v = Foo { a: Bar { a: 2 } }; let mut d = Decoder::new(Table(map! { @@ -1232,7 +1242,7 @@ mod tests { #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] struct Foo { a: Vec } #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] - struct Bar { a: int } + struct Bar { a: isize } let v = Foo { a: vec![Bar { a: 1 }] }; let mut d = Decoder::new(Table(map! { diff --git a/src/show.rs b/src/show.rs index cfa43a2..af1eba0 100644 --- a/src/show.rs +++ b/src/show.rs @@ -1,7 +1,6 @@ use std::fmt; use Table as TomlTable; -use Array as TomlArray; use Value::{self, String, Integer, Float, Boolean, Datetime, Array, Table}; struct Printer<'a, 'b:'a> { @@ -41,9 +40,13 @@ impl fmt::String for Value { p.print(t) } Array(ref a) => { - let mut p = Printer { output: f, stack: Vec::new() }; - p.print_array(a) - }, + try!(write!(f, "[")); + for (i, v) in a.iter().enumerate() { + if i != 0 { try!(write!(f, ", ")); } + try!(write!(f, "{}", v)); + } + write!(f, "]") + } } } } @@ -93,20 +96,6 @@ impl<'a, 'b> Printer<'a, 'b> { } Ok(()) } - - fn print_array(&mut self, array: &'a TomlArray) -> fmt::Result { - try!(self.output.write_str("[")); - let mut first = true; - for item in array.iter() { - if first { - first = false; - } else { - try!(self.output.write_str(", ")); - } - try!((&item as &fmt::String).fmt(self.output)); - } - self.output.write_str("]") - } } #[cfg(test)] @@ -116,7 +105,7 @@ mod tests { use Value::{String, Integer, Float, Boolean, Datetime, Array, Table}; use std::collections::BTreeMap; - macro_rules! map( ($($k:expr, $v:expr),*) => ({ + macro_rules! map( ($($k:expr => $v:expr),*) => ({ let mut _m = BTreeMap::new(); $(_m.insert($k.to_string(), $v);)* _m @@ -146,12 +135,12 @@ mod tests { fn table() { assert_eq!(Table(map! { }).to_string().as_slice(), ""); - assert_eq!(Table(map! { "test", Integer(2) }).to_string().as_slice(), + assert_eq!(Table(map! { "test" => Integer(2) }).to_string().as_slice(), "test = 2\n"); assert_eq!(Table(map! { - "test", Integer(2), - "test2", Table(map! { - "test", String("wut".to_string()) + "test" => Integer(2), + "test2" => Table(map! { + "test" => String("wut".to_string()) }) }).to_string().as_slice(), "test = 2\n\ @@ -159,9 +148,9 @@ mod tests { [test2]\n\ test = \"wut\"\n"); assert_eq!(Table(map! { - "test", Integer(2), - "test2", Table(map! { - "test", String("wut".to_string()) + "test" => Integer(2), + "test2" => Table(map! { + "test" => String("wut".to_string()) }) }).to_string().as_slice(), "test = 2\n\ @@ -169,9 +158,9 @@ mod tests { [test2]\n\ test = \"wut\"\n"); assert_eq!(Table(map! { - "test", Integer(2), - "test2", Array(vec![Table(map! { - "test", String("wut".to_string()) + "test" => Integer(2), + "test2" => Array(vec![Table(map! { + "test" => String("wut".to_string()) })]) }).to_string().as_slice(), "test = 2\n\ -- cgit v1.2.3