Bump to 0.1.11

This commit is contained in:
Alex Crichton 2015-01-09 11:48:06 -08:00
parent 98212466af
commit d4319caa20
5 changed files with 116 additions and 118 deletions

View file

@ -1,7 +1,7 @@
[package] [package]
name = "toml" name = "toml"
version = "0.1.10" version = "0.1.11"
authors = ["Alex Crichton <alex@alexcrichton.com>"] authors = ["Alex Crichton <alex@alexcrichton.com>"]
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
readme = "README.md" readme = "README.md"

View file

@ -37,9 +37,8 @@
//! //!
#![deny(missing_docs)] #![deny(missing_docs)]
#![allow(staged_experimental)]
#![allow(staged_unstable)]
#![cfg_attr(test, deny(warnings))] #![cfg_attr(test, deny(warnings))]
#![allow(unstable)]
extern crate "rustc-serialize" as rustc_serialize; extern crate "rustc-serialize" as rustc_serialize;
@ -159,7 +158,7 @@ impl Value {
/// Note: arrays have zero-based indexes. /// Note: arrays have zero-based indexes.
/// ///
/// ``` /// ```
/// # #![allow(staged_unstable)] /// # #![allow(unstable)]
/// let toml = r#" /// let toml = r#"
/// [test] /// [test]
/// foo = "bar" /// foo = "bar"
@ -192,7 +191,7 @@ impl Value {
} }
}, },
&Value::Array(ref v) => { &Value::Array(ref v) => {
match key.parse::<uint>() { match key.parse::<usize>() {
Some(idx) if idx < v.len() => cur_value = &v[idx], Some(idx) if idx < v.len() => cur_value = &v[idx],
_ => return None _ => return None
} }

View file

@ -30,9 +30,9 @@ pub struct Parser<'a> {
#[derive(Show)] #[derive(Show)]
pub struct ParserError { pub struct ParserError {
/// The low byte at which this error is pointing at. /// 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. /// 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. /// A human-readable description explaining what the error is.
pub desc: String, pub desc: String,
} }
@ -69,7 +69,7 @@ impl<'a> Parser<'a> {
/// Converts a byte offset from an error message to a (line, column) pair /// Converts a byte offset from an error message to a (line, column) pair
/// ///
/// All indexes are 0-based. /// 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; let mut cur = 0;
for (i, line) in self.input.lines().enumerate() { for (i, line) in self.input.lines().enumerate() {
if cur + line.len() > offset { if cur + line.len() > offset {
@ -80,7 +80,7 @@ impl<'a> Parser<'a> {
return (self.input.lines().count(), 0) 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()) 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 // Parses a single or multi-line string
fn string(&mut self, start: uint) -> Option<Value> { fn string(&mut self, start: usize) -> Option<Value> {
if !self.expect('"') { return None } if !self.expect('"') { return None }
let mut multiline = false; let mut multiline = false;
let mut ret = String::new(); let mut ret = String::new();
@ -331,7 +331,7 @@ impl<'a> Parser<'a> {
return Some(Value::String(ret)); return Some(Value::String(ret));
fn escape(me: &mut Parser, pos: uint, multiline: bool) -> Option<char> { fn escape(me: &mut Parser, pos: usize, multiline: bool) -> Option<char> {
match me.cur.next() { match me.cur.next() {
Some((_, 'b')) => Some('\u{8}'), Some((_, 'b')) => Some('\u{8}'),
Some((_, 't')) => Some('\u{9}'), Some((_, 't')) => Some('\u{9}'),
@ -417,7 +417,7 @@ impl<'a> Parser<'a> {
} }
} }
fn literal_string(&mut self, start: uint) -> Option<Value> { fn literal_string(&mut self, start: usize) -> Option<Value> {
if !self.expect('\'') { return None } if !self.expect('\'') { return None }
let mut multiline = false; let mut multiline = false;
let mut ret = String::new(); let mut ret = String::new();
@ -453,7 +453,7 @@ impl<'a> Parser<'a> {
return Some(Value::String(ret)); return Some(Value::String(ret));
} }
fn number_or_datetime(&mut self, start: uint) -> Option<Value> { fn number_or_datetime(&mut self, start: usize) -> Option<Value> {
let negative = self.eat('-'); let negative = self.eat('-');
let mut is_float = false; let mut is_float = false;
loop { loop {
@ -488,15 +488,15 @@ impl<'a> Parser<'a> {
return ret; return ret;
} }
fn boolean(&mut self, start: uint) -> Option<Value> { fn boolean(&mut self, start: usize) -> Option<Value> {
let rest = self.input.slice_from(start); let rest = self.input.slice_from(start);
if rest.starts_with("true") { if rest.starts_with("true") {
for _ in range(0u, 4u) { for _ in 0..4 {
self.cur.next(); self.cur.next();
} }
Some(Boolean(true)) Some(Boolean(true))
} else if rest.starts_with("false") { } else if rest.starts_with("false") {
for _ in range(0u, 5u) { for _ in 0..5 {
self.cur.next(); self.cur.next();
} }
Some(Boolean(false)) Some(Boolean(false))
@ -512,9 +512,9 @@ impl<'a> Parser<'a> {
} }
} }
fn datetime(&mut self, start: uint, end_so_far: uint) -> Option<Value> { fn datetime(&mut self, start: usize, end_so_far: usize) -> Option<Value> {
let mut date = self.input.slice(start, end_so_far).to_string(); 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() { match self.cur.next() {
Some((_, ch)) => date.push(ch), Some((_, ch)) => date.push(ch),
None => { None => {
@ -561,7 +561,7 @@ impl<'a> Parser<'a> {
} }
} }
fn array(&mut self, _start: uint) -> Option<Value> { fn array(&mut self, _start: usize) -> Option<Value> {
if !self.expect('[') { return None } if !self.expect('[') { return None }
let mut ret = Vec::new(); let mut ret = Vec::new();
fn consume(me: &mut Parser) { fn consume(me: &mut Parser) {
@ -612,7 +612,7 @@ impl<'a> Parser<'a> {
} }
fn insert(&mut self, into: &mut TomlTable, key: String, value: Value, fn insert(&mut self, into: &mut TomlTable, key: String, value: Value,
key_lo: uint) { key_lo: usize) {
if into.contains_key(&key) { if into.contains_key(&key) {
self.errors.push(ParserError { self.errors.push(ParserError {
lo: key_lo, 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, 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(".") || if orig_key.starts_with(".") || orig_key.ends_with(".") ||
orig_key.contains("..") { orig_key.contains("..") {
self.errors.push(ParserError { self.errors.push(ParserError {
@ -687,7 +687,7 @@ impl<'a> Parser<'a> {
} }
fn insert_table(&mut self, into: &mut TomlTable, key: String, value: TomlTable, 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) { let (into, key) = match self.recurse(into, key.as_slice(), key_lo) {
Some(pair) => pair, Some(pair) => pair,
None => return, None => return,
@ -730,7 +730,7 @@ impl<'a> Parser<'a> {
} }
fn insert_array(&mut self, into: &mut TomlTable, key: String, value: Value, 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) { let (into, key) = match self.recurse(into, key.as_slice(), key_lo) {
Some(pair) => pair, Some(pair) => pair,
None => return, None => return,

View file

@ -23,9 +23,7 @@ use self::DecodeErrorKind::{ExpectedMapElement, NoEnumVariants, NilTooLong};
/// # Example /// # Example
/// ///
/// ``` /// ```
/// # #![feature(old_orphan_check)] /// # #![allow(unstable)]
/// # #![allow(staged_unstable)]
/// # #![allow(staged_experimental)]
/// extern crate "rustc-serialize" as rustc_serialize; /// extern crate "rustc-serialize" as rustc_serialize;
/// extern crate toml; /// extern crate toml;
/// ///
@ -92,7 +90,7 @@ pub struct DecodeError {
} }
/// Enumeration of possible errors which can occur while decoding a structure. /// Enumeration of possible errors which can occur while decoding a structure.
#[derive(PartialEq)] #[derive(PartialEq, Show)]
pub enum DecodeErrorKind { pub enum DecodeErrorKind {
/// An error flagged by the application, e.g. value out of range /// An error flagged by the application, e.g. value out of range
ApplicationError(String), ApplicationError(String),
@ -101,9 +99,9 @@ pub enum DecodeErrorKind {
/// A field was found, but it had the wrong type. /// A field was found, but it had the wrong type.
ExpectedType(/* expected */ &'static str, /* found */ &'static str), ExpectedType(/* expected */ &'static str, /* found */ &'static str),
/// The nth map key was expected, but none was found. /// The nth map key was expected, but none was found.
ExpectedMapKey(uint), ExpectedMapKey(usize),
/// The nth map element was expected, but none was found. /// The nth map element was expected, but none was found.
ExpectedMapElement(uint), ExpectedMapElement(usize),
/// An enum decoding was requested, but no variants were supplied /// An enum decoding was requested, but no variants were supplied
NoEnumVariants, NoEnumVariants,
/// The unit type was being decoded, but a non-zero length string was found /// 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; type Error = Error;
fn emit_nil(&mut self) -> Result<(), Error> { Ok(()) } 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) self.emit_i64(v as i64)
} }
fn emit_u8(&mut self, v: u8) -> Result<(), Error> { 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> { fn emit_u64(&mut self, v: u64) -> Result<(), Error> {
self.emit_i64(v as i64) 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) self.emit_i64(v as i64)
} }
fn emit_i8(&mut self, v: i8) -> Result<(), Error> { fn emit_i8(&mut self, v: i8) -> Result<(), Error> {
@ -215,20 +213,20 @@ impl rustc_serialize::Encoder for Encoder {
{ {
f(self) f(self)
} }
fn emit_enum_variant<F>(&mut self, _v_name: &str, _v_id: uint, _len: uint, f: F) fn emit_enum_variant<F>(&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<F>(&mut self, _a_idx: usize, f: F)
-> Result<(), Error> -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error>
{ {
f(self) f(self)
} }
fn emit_enum_variant_arg<F>(&mut self, _a_idx: uint, f: F) fn emit_enum_struct_variant<F>(&mut self, _v_name: &str, _v_id: usize,
-> Result<(), Error> _len: usize,
where F: FnOnce(&mut Encoder) -> Result<(), Error>
{
f(self)
}
fn emit_enum_struct_variant<F>(&mut self, _v_name: &str, _v_id: uint,
_len: uint,
_f: F) _f: F)
-> Result<(), Error> -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> 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<F>(&mut self, fn emit_enum_struct_variant_field<F>(&mut self,
_f_name: &str, _f_name: &str,
_f_idx: uint, _f_idx: usize,
_f: F) _f: F)
-> Result<(), Error> -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error>
{ {
panic!() panic!()
} }
fn emit_struct<F>(&mut self, _name: &str, _len: uint, f: F) fn emit_struct<F>(&mut self, _name: &str, _len: usize, f: F)
-> Result<(), Error> -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error>
{ {
@ -266,7 +264,7 @@ impl rustc_serialize::Encoder for Encoder {
NextMapKey => Err(InvalidMapKeyLocation), NextMapKey => Err(InvalidMapKeyLocation),
} }
} }
fn emit_struct_field<F>(&mut self, f_name: &str, _f_idx: uint, f: F) fn emit_struct_field<F>(&mut self, f_name: &str, _f_idx: usize, f: F)
-> Result<(), Error> -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error>
{ {
@ -278,25 +276,25 @@ impl rustc_serialize::Encoder for Encoder {
self.state = old; self.state = old;
Ok(()) Ok(())
} }
fn emit_tuple<F>(&mut self, len: uint, f: F) fn emit_tuple<F>(&mut self, len: usize, f: F)
-> Result<(), Error> -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error>
{ {
self.emit_seq(len, f) self.emit_seq(len, f)
} }
fn emit_tuple_arg<F>(&mut self, idx: uint, f: F) fn emit_tuple_arg<F>(&mut self, idx: usize, f: F)
-> Result<(), Error> -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error>
{ {
self.emit_seq_elt(idx, f) self.emit_seq_elt(idx, f)
} }
fn emit_tuple_struct<F>(&mut self, _name: &str, _len: uint, _f: F) fn emit_tuple_struct<F>(&mut self, _name: &str, _len: usize, _f: F)
-> Result<(), Error> -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error>
{ {
unimplemented!() unimplemented!()
} }
fn emit_tuple_struct_arg<F>(&mut self, _f_idx: uint, _f: F) fn emit_tuple_struct_arg<F>(&mut self, _f_idx: usize, _f: F)
-> Result<(), Error> -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error>
{ {
@ -322,7 +320,7 @@ impl rustc_serialize::Encoder for Encoder {
{ {
f(self) f(self)
} }
fn emit_seq<F>(&mut self, _len: uint, f: F) fn emit_seq<F>(&mut self, _len: usize, f: F)
-> Result<(), Error> -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error>
{ {
@ -333,19 +331,19 @@ impl rustc_serialize::Encoder for Encoder {
_ => unreachable!(), _ => unreachable!(),
} }
} }
fn emit_seq_elt<F>(&mut self, _idx: uint, f: F) fn emit_seq_elt<F>(&mut self, _idx: usize, f: F)
-> Result<(), Error> -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error>
{ {
f(self) f(self)
} }
fn emit_map<F>(&mut self, len: uint, f: F) fn emit_map<F>(&mut self, len: usize, f: F)
-> Result<(), Error> -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error>
{ {
self.emit_struct("foo", len, f) self.emit_struct("foo", len, f)
} }
fn emit_map_elt_key<F>(&mut self, _idx: uint, mut f: F) fn emit_map_elt_key<F>(&mut self, _idx: usize, mut f: F)
-> Result<(), Error> -> Result<(), Error>
where F: FnMut(&mut Encoder) -> Result<(), Error> where F: FnMut(&mut Encoder) -> Result<(), Error>
{ {
@ -359,7 +357,7 @@ impl rustc_serialize::Encoder for Encoder {
_ => Err(InvalidMapKeyLocation), _ => Err(InvalidMapKeyLocation),
} }
} }
fn emit_map_elt_val<F>(&mut self, _idx: uint, f: F) fn emit_map_elt_val<F>(&mut self, _idx: usize, f: F)
-> Result<(), Error> -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error>
{ {
@ -441,8 +439,8 @@ impl rustc_serialize::Decoder for Decoder {
self.toml.take(); self.toml.take();
Ok(()) Ok(())
} }
fn read_usize(&mut self) -> Result<uint, DecodeError> { fn read_usize(&mut self) -> Result<usize, DecodeError> {
self.read_i64().map(|i| i as uint) self.read_i64().map(|i| i as usize)
} }
fn read_u64(&mut self) -> Result<u64, DecodeError> { fn read_u64(&mut self) -> Result<u64, DecodeError> {
self.read_i64().map(|i| i as u64) self.read_i64().map(|i| i as u64)
@ -456,8 +454,8 @@ impl rustc_serialize::Decoder for Decoder {
fn read_u8(&mut self) -> Result<u8, DecodeError> { fn read_u8(&mut self) -> Result<u8, DecodeError> {
self.read_i64().map(|i| i as u8) self.read_i64().map(|i| i as u8)
} }
fn read_isize(&mut self) -> Result<int, DecodeError> { fn read_isize(&mut self) -> Result<isize, DecodeError> {
self.read_i64().map(|i| i as int) self.read_i64().map(|i| i as isize)
} }
fn read_i64(&mut self) -> Result<i64, DecodeError> { fn read_i64(&mut self) -> Result<i64, DecodeError> {
match self.toml { match self.toml {
@ -519,7 +517,7 @@ impl rustc_serialize::Decoder for Decoder {
fn read_enum_variant<T, F>(&mut self, names: &[&str], mut f: F) fn read_enum_variant<T, F>(&mut self, names: &[&str], mut f: F)
-> Result<T, DecodeError> -> Result<T, DecodeError>
where F: FnMut(&mut Decoder, uint) -> Result<T, DecodeError> where F: FnMut(&mut Decoder, usize) -> Result<T, DecodeError>
{ {
let mut first_error = None; let mut first_error = None;
for i in range(0, names.len()) { 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))) Err(first_error.unwrap_or_else(|| self.err(NoEnumVariants)))
} }
fn read_enum_variant_arg<T, F>(&mut self, _a_idx: uint, f: F) fn read_enum_variant_arg<T, F>(&mut self, _a_idx: usize, f: F)
-> Result<T, DecodeError> -> Result<T, DecodeError>
where F: FnOnce(&mut Decoder) -> Result<T, DecodeError> where F: FnOnce(&mut Decoder) -> Result<T, DecodeError>
{ {
@ -544,13 +542,13 @@ impl rustc_serialize::Decoder for Decoder {
fn read_enum_struct_variant<T, F>(&mut self, _names: &[&str], _f: F) fn read_enum_struct_variant<T, F>(&mut self, _names: &[&str], _f: F)
-> Result<T, DecodeError> -> Result<T, DecodeError>
where F: FnMut(&mut Decoder, uint) -> Result<T, DecodeError> where F: FnMut(&mut Decoder, usize) -> Result<T, DecodeError>
{ {
panic!() panic!()
} }
fn read_enum_struct_variant_field<T, F>(&mut self, fn read_enum_struct_variant_field<T, F>(&mut self,
_f_name: &str, _f_name: &str,
_f_idx: uint, _f_idx: usize,
_f: F) _f: F)
-> Result<T, DecodeError> -> Result<T, DecodeError>
where F: FnOnce(&mut Decoder) -> Result<T, DecodeError> where F: FnOnce(&mut Decoder) -> Result<T, DecodeError>
@ -558,7 +556,7 @@ impl rustc_serialize::Decoder for Decoder {
panic!() panic!()
} }
fn read_struct<T, F>(&mut self, _s_name: &str, _len: uint, f: F) fn read_struct<T, F>(&mut self, _s_name: &str, _len: usize, f: F)
-> Result<T, DecodeError> -> Result<T, DecodeError>
where F: FnOnce(&mut Decoder) -> Result<T, DecodeError> where F: FnOnce(&mut Decoder) -> Result<T, DecodeError>
{ {
@ -575,7 +573,7 @@ impl rustc_serialize::Decoder for Decoder {
ref found => Err(self.mismatch("table", found)), ref found => Err(self.mismatch("table", found)),
} }
} }
fn read_struct_field<T, F>(&mut self, f_name: &str, _f_idx: uint, f: F) fn read_struct_field<T, F>(&mut self, f_name: &str, _f_idx: usize, f: F)
-> Result<T, DecodeError> -> Result<T, DecodeError>
where F: FnOnce(&mut Decoder) -> Result<T, DecodeError> where F: FnOnce(&mut Decoder) -> Result<T, DecodeError>
{ {
@ -599,7 +597,7 @@ impl rustc_serialize::Decoder for Decoder {
Ok(ret) Ok(ret)
} }
fn read_tuple<T, F>(&mut self, tuple_len: uint, f: F) fn read_tuple<T, F>(&mut self, tuple_len: usize, f: F)
-> Result<T, DecodeError> -> Result<T, DecodeError>
where F: FnOnce(&mut Decoder) -> Result<T, DecodeError> where F: FnOnce(&mut Decoder) -> Result<T, DecodeError>
{ {
@ -610,20 +608,20 @@ impl rustc_serialize::Decoder for Decoder {
f(d) f(d)
}) })
} }
fn read_tuple_arg<T, F>(&mut self, a_idx: uint, f: F) fn read_tuple_arg<T, F>(&mut self, a_idx: usize, f: F)
-> Result<T, DecodeError> -> Result<T, DecodeError>
where F: FnOnce(&mut Decoder) -> Result<T, DecodeError> where F: FnOnce(&mut Decoder) -> Result<T, DecodeError>
{ {
self.read_seq_elt(a_idx, f) self.read_seq_elt(a_idx, f)
} }
fn read_tuple_struct<T, F>(&mut self, _s_name: &str, _len: uint, _f: F) fn read_tuple_struct<T, F>(&mut self, _s_name: &str, _len: usize, _f: F)
-> Result<T, DecodeError> -> Result<T, DecodeError>
where F: FnOnce(&mut Decoder) -> Result<T, DecodeError> where F: FnOnce(&mut Decoder) -> Result<T, DecodeError>
{ {
panic!() panic!()
} }
fn read_tuple_struct_arg<T, F>(&mut self, _a_idx: uint, _f: F) fn read_tuple_struct_arg<T, F>(&mut self, _a_idx: usize, _f: F)
-> Result<T, DecodeError> -> Result<T, DecodeError>
where F: FnOnce(&mut Decoder) -> Result<T, DecodeError> where F: FnOnce(&mut Decoder) -> Result<T, DecodeError>
{ {
@ -643,7 +641,7 @@ impl rustc_serialize::Decoder for Decoder {
fn read_seq<T, F>(&mut self, f: F) fn read_seq<T, F>(&mut self, f: F)
-> Result<T, DecodeError> -> Result<T, DecodeError>
where F: FnOnce(&mut Decoder,uint) -> Result<T, DecodeError> where F: FnOnce(&mut Decoder, usize) -> Result<T, DecodeError>
{ {
let len = match self.toml { let len = match self.toml {
Some(Array(ref arr)) => arr.len(), Some(Array(ref arr)) => arr.len(),
@ -661,7 +659,7 @@ impl rustc_serialize::Decoder for Decoder {
self.toml.take(); self.toml.take();
Ok(ret) Ok(ret)
} }
fn read_seq_elt<T, F>(&mut self, idx: uint, f: F) fn read_seq_elt<T, F>(&mut self, idx: usize, f: F)
-> Result<T, DecodeError> -> Result<T, DecodeError>
where F: FnOnce(&mut Decoder) -> Result<T, DecodeError> where F: FnOnce(&mut Decoder) -> Result<T, DecodeError>
{ {
@ -683,7 +681,7 @@ impl rustc_serialize::Decoder for Decoder {
fn read_map<T, F>(&mut self, f: F) fn read_map<T, F>(&mut self, f: F)
-> Result<T, DecodeError> -> Result<T, DecodeError>
where F: FnOnce(&mut Decoder, uint) -> Result<T, DecodeError> where F: FnOnce(&mut Decoder, usize) -> Result<T, DecodeError>
{ {
let len = match self.toml { let len = match self.toml {
Some(Table(ref table)) => table.len(), Some(Table(ref table)) => table.len(),
@ -693,7 +691,7 @@ impl rustc_serialize::Decoder for Decoder {
self.toml.take(); self.toml.take();
Ok(ret) Ok(ret)
} }
fn read_map_elt_key<T, F>(&mut self, idx: uint, f: F) fn read_map_elt_key<T, F>(&mut self, idx: usize, f: F)
-> Result<T, DecodeError> -> Result<T, DecodeError>
where F: FnOnce(&mut Decoder) -> Result<T, DecodeError> where F: FnOnce(&mut Decoder) -> Result<T, DecodeError>
{ {
@ -710,7 +708,7 @@ impl rustc_serialize::Decoder for Decoder {
ref found => Err(self.mismatch("table", found)), ref found => Err(self.mismatch("table", found)),
} }
} }
fn read_map_elt_val<T, F>(&mut self, idx: uint, f: F) fn read_map_elt_val<T, F>(&mut self, idx: usize, f: F)
-> Result<T, DecodeError> -> Result<T, DecodeError>
where F: FnOnce(&mut Decoder) -> Result<T, DecodeError> where F: FnOnce(&mut Decoder) -> Result<T, DecodeError>
{ {
@ -737,6 +735,12 @@ impl rustc_serialize::Decoder for Decoder {
} }
impl fmt::Show for DecodeError { 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 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(match self.kind { try!(match self.kind {
ApplicationError(ref err) => { ApplicationError(ref err) => {
@ -799,6 +803,12 @@ impl StdError for DecodeError {
} }
impl fmt::Show for Error { 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 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self { match *self {
NeedsKey => write!(f, "need a key to encode"), NeedsKey => write!(f, "need a key to encode"),
@ -845,7 +855,7 @@ mod tests {
#[test] #[test]
fn smoke() { fn smoke() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: int } struct Foo { a: isize }
let v = Foo { a: 2 }; let v = Foo { a: 2 };
assert_eq!(encode!(v), map! { a, Integer(2) }); assert_eq!(encode!(v), map! { a, Integer(2) });
@ -855,7 +865,7 @@ mod tests {
#[test] #[test]
fn smoke_hyphen() { fn smoke_hyphen() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a_b: int } struct Foo { a_b: isize }
let v = Foo { a_b: 2 }; let v = Foo { a_b: 2 };
assert_eq!(encode!(v), map! { a_b, Integer(2) }); assert_eq!(encode!(v), map! { a_b, Integer(2) });
@ -869,7 +879,7 @@ mod tests {
#[test] #[test]
fn nested() { fn nested() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: int, b: Bar } struct Foo { a: isize, b: Bar }
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Bar { a: String } struct Bar { a: String }
@ -887,10 +897,10 @@ mod tests {
#[test] #[test]
fn application_decode_error() { fn application_decode_error() {
#[derive(PartialEq, Show)] #[derive(PartialEq, Show)]
struct Range10(uint); struct Range10(usize);
impl Decodable for Range10 { impl Decodable for Range10 {
fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<Range10, D::Error> { fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<Range10, D::Error> {
let x: uint = try!(Decodable::decode(d)); let x: usize = try!(Decodable::decode(d));
if x > 10 { if x > 10 {
Err(d.error("Value out of range!")) Err(d.error("Value out of range!"))
} else { } else {
@ -899,7 +909,7 @@ mod tests {
} }
} }
let mut d_good = Decoder::new(Integer(5)); 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)); let mut d_bad2 = Decoder::new(Integer(11));
assert_eq!(Ok(Range10(5)), Decodable::decode(&mut d_good)); assert_eq!(Ok(Range10(5)), Decodable::decode(&mut d_good));
@ -913,7 +923,7 @@ mod tests {
#[test] #[test]
fn array() { fn array() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: Vec<int> } struct Foo { a: Vec<isize> }
let v = Foo { a: vec![1, 2, 3, 4] }; let v = Foo { a: vec![1, 2, 3, 4] };
assert_eq!(encode!(v), assert_eq!(encode!(v),
@ -931,7 +941,7 @@ mod tests {
#[test] #[test]
fn tuple() { fn tuple() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[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) }; let v = Foo { a: (1, 2, 3, 4) };
assert_eq!(encode!(v), assert_eq!(encode!(v),
@ -986,7 +996,7 @@ mod tests {
fn hashmap() { fn hashmap() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { struct Foo {
map: BTreeMap<String, int>, map: BTreeMap<String, isize>,
set: HashSet<char>, set: HashSet<char>,
} }
@ -1018,7 +1028,7 @@ mod tests {
#[test] #[test]
fn tuple_struct() { fn tuple_struct() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo(int, String, f64); struct Foo(isize, String, f64);
let v = Foo(1, "foo".to_string(), 4.5); let v = Foo(1, "foo".to_string(), 4.5);
assert_eq!( assert_eq!(
@ -1037,7 +1047,7 @@ mod tests {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: Vec<Bar>, } struct Foo { a: Vec<Bar>, }
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Bar { a: int } struct Bar { a: isize }
let v = Foo { a: vec![Bar { a: 1 }, Bar { a: 2 }] }; let v = Foo { a: vec![Bar { a: 1 }, Bar { a: 2 }] };
assert_eq!( assert_eq!(
@ -1055,7 +1065,7 @@ mod tests {
#[test] #[test]
fn type_errors() { fn type_errors() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { bar: int } struct Foo { bar: isize }
let mut d = Decoder::new(Table(map! { let mut d = Decoder::new(Table(map! {
bar, Float(1.0) bar, Float(1.0)
@ -1074,7 +1084,7 @@ mod tests {
#[test] #[test]
fn missing_errors() { fn missing_errors() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { bar: int } struct Foo { bar: isize }
let mut d = Decoder::new(Table(map! { let mut d = Decoder::new(Table(map! {
})); }));
@ -1094,7 +1104,7 @@ mod tests {
struct Foo { a: E } struct Foo { a: E }
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
enum E { enum E {
Bar(int), Bar(isize),
Baz(f64), Baz(f64),
Last(Foo2), Last(Foo2),
} }
@ -1128,7 +1138,7 @@ mod tests {
#[test] #[test]
fn unused_fields() { fn unused_fields() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: int } struct Foo { a: isize }
let v = Foo { a: 2 }; let v = Foo { a: 2 };
let mut d = Decoder::new(Table(map! { let mut d = Decoder::new(Table(map! {
@ -1147,7 +1157,7 @@ mod tests {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: Bar } struct Foo { a: Bar }
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Bar { a: int } struct Bar { a: isize }
let v = Foo { a: Bar { a: 2 } }; let v = Foo { a: Bar { a: 2 } };
let mut d = Decoder::new(Table(map! { let mut d = Decoder::new(Table(map! {
@ -1170,7 +1180,7 @@ mod tests {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: Bar } struct Foo { a: Bar }
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Bar { a: int } struct Bar { a: isize }
let v = Foo { a: Bar { a: 2 } }; let v = Foo { a: Bar { a: 2 } };
let mut d = Decoder::new(Table(map! { let mut d = Decoder::new(Table(map! {
@ -1232,7 +1242,7 @@ mod tests {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: Vec<Bar> } struct Foo { a: Vec<Bar> }
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Bar { a: int } struct Bar { a: isize }
let v = Foo { a: vec![Bar { a: 1 }] }; let v = Foo { a: vec![Bar { a: 1 }] };
let mut d = Decoder::new(Table(map! { let mut d = Decoder::new(Table(map! {

View file

@ -1,7 +1,6 @@
use std::fmt; use std::fmt;
use Table as TomlTable; use Table as TomlTable;
use Array as TomlArray;
use Value::{self, String, Integer, Float, Boolean, Datetime, Array, Table}; use Value::{self, String, Integer, Float, Boolean, Datetime, Array, Table};
struct Printer<'a, 'b:'a> { struct Printer<'a, 'b:'a> {
@ -41,9 +40,13 @@ impl fmt::String for Value {
p.print(t) p.print(t)
} }
Array(ref a) => { Array(ref a) => {
let mut p = Printer { output: f, stack: Vec::new() }; try!(write!(f, "["));
p.print_array(a) 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(()) 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)] #[cfg(test)]
@ -116,7 +105,7 @@ mod tests {
use Value::{String, Integer, Float, Boolean, Datetime, Array, Table}; use Value::{String, Integer, Float, Boolean, Datetime, Array, Table};
use std::collections::BTreeMap; use std::collections::BTreeMap;
macro_rules! map( ($($k:expr, $v:expr),*) => ({ macro_rules! map( ($($k:expr => $v:expr),*) => ({
let mut _m = BTreeMap::new(); let mut _m = BTreeMap::new();
$(_m.insert($k.to_string(), $v);)* $(_m.insert($k.to_string(), $v);)*
_m _m
@ -146,12 +135,12 @@ mod tests {
fn table() { fn table() {
assert_eq!(Table(map! { }).to_string().as_slice(), 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"); "test = 2\n");
assert_eq!(Table(map! { assert_eq!(Table(map! {
"test", Integer(2), "test" => Integer(2),
"test2", Table(map! { "test2" => Table(map! {
"test", String("wut".to_string()) "test" => String("wut".to_string())
}) })
}).to_string().as_slice(), }).to_string().as_slice(),
"test = 2\n\ "test = 2\n\
@ -159,9 +148,9 @@ mod tests {
[test2]\n\ [test2]\n\
test = \"wut\"\n"); test = \"wut\"\n");
assert_eq!(Table(map! { assert_eq!(Table(map! {
"test", Integer(2), "test" => Integer(2),
"test2", Table(map! { "test2" => Table(map! {
"test", String("wut".to_string()) "test" => String("wut".to_string())
}) })
}).to_string().as_slice(), }).to_string().as_slice(),
"test = 2\n\ "test = 2\n\
@ -169,9 +158,9 @@ mod tests {
[test2]\n\ [test2]\n\
test = \"wut\"\n"); test = \"wut\"\n");
assert_eq!(Table(map! { assert_eq!(Table(map! {
"test", Integer(2), "test" => Integer(2),
"test2", Array(vec![Table(map! { "test2" => Array(vec![Table(map! {
"test", String("wut".to_string()) "test" => String("wut".to_string())
})]) })])
}).to_string().as_slice(), }).to_string().as_slice(),
"test = 2\n\ "test = 2\n\