Bump to 0.1.15

This commit is contained in:
Alex Crichton 2015-01-23 08:19:29 -08:00
parent 0c71c5d1c1
commit 909a85069b
4 changed files with 55 additions and 62 deletions

View file

@ -1,7 +1,7 @@
[package] [package]
name = "toml" name = "toml"
version = "0.1.14" version = "0.1.15"
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

@ -1,6 +1,7 @@
use std::char; use std::char;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::error::Error; use std::error::Error;
use std::fmt;
use std::num::FromStrRadix; use std::num::FromStrRadix;
use std::str; use std::str;
@ -27,7 +28,7 @@ pub struct Parser<'a> {
/// ///
/// The data in this structure can be used to trace back to the original cause /// The data in this structure can be used to trace back to the original cause
/// of the error in order to provide diagnostics about parse errors. /// of the error in order to provide diagnostics about parse errors.
#[derive(Show)] #[derive(Debug)]
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: usize, pub lo: usize,
@ -374,7 +375,7 @@ impl<'a> Parser<'a> {
Some((pos, c @ 'U')) => { Some((pos, c @ 'U')) => {
let len = if c == 'u' {4} else {8}; let len = if c == 'u' {4} else {8};
let num = if me.input.is_char_boundary(pos + 1 + len) { let num = if me.input.is_char_boundary(pos + 1 + len) {
me.input.slice(pos + 1, pos + 1 + len) &me.input[pos + 1 .. pos + 1 + len]
} else { } else {
"invalid" "invalid"
}; };
@ -489,7 +490,7 @@ impl<'a> Parser<'a> {
if !self.integer(start, false, true) { return None } if !self.integer(start, false, true) { return None }
} }
let end = self.next_pos(); let end = self.next_pos();
let input = self.input.slice(start, end); let input = &self.input[start..end];
let ret = if !is_float && !input.starts_with("+") && let ret = if !is_float && !input.starts_with("+") &&
!input.starts_with("-") && self.eat('-') { !input.starts_with("-") && self.eat('-') {
self.datetime(start, end + 1) self.datetime(start, end + 1)
@ -549,7 +550,7 @@ impl<'a> Parser<'a> {
} }
fn boolean(&mut self, start: usize) -> Option<Value> { fn boolean(&mut self, start: usize) -> Option<Value> {
let rest = self.input.slice_from(start); let rest = &self.input[start..];
if rest.starts_with("true") { if rest.starts_with("true") {
for _ in 0..4 { for _ in 0..4 {
self.cur.next(); self.cur.next();
@ -573,7 +574,7 @@ impl<'a> Parser<'a> {
} }
fn datetime(&mut self, start: usize, end_so_far: usize) -> 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[start..end_so_far].to_string();
for _ in 0..15 { for _ in 0..15 {
match self.cur.next() { match self.cur.next() {
Some((_, ch)) => date.push(ch), Some((_, ch)) => date.push(ch),
@ -809,7 +810,12 @@ impl<'a> Parser<'a> {
impl Error for ParserError { impl Error for ParserError {
fn description(&self) -> &str { "TOML parse error" } fn description(&self) -> &str { "TOML parse error" }
fn detail(&self) -> Option<String> { Some(self.desc.clone()) } }
impl fmt::Display for ParserError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.desc.fmt(f)
}
} }
#[cfg(test)] #[cfg(test)]

View file

@ -66,6 +66,7 @@ pub struct Decoder {
/// Enumeration of errors which can occur while encoding a rust value into a /// Enumeration of errors which can occur while encoding a rust value into a
/// TOML value. /// TOML value.
#[allow(missing_copy_implementations)] #[allow(missing_copy_implementations)]
#[derive(Debug)]
pub enum Error { pub enum Error {
/// Indication that a key was needed when a value was emitted, but no key /// Indication that a key was needed when a value was emitted, but no key
/// was previously emitted. /// was previously emitted.
@ -81,7 +82,7 @@ pub enum Error {
} }
/// Description for errors which can occur while decoding a type. /// Description for errors which can occur while decoding a type.
#[derive(PartialEq)] #[derive(PartialEq, Debug)]
pub struct DecodeError { pub struct DecodeError {
/// Field that this error applies to. /// Field that this error applies to.
pub field: Option<String>, pub field: Option<String>,
@ -90,7 +91,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, Show)] #[derive(PartialEq, Debug)]
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),
@ -343,9 +344,9 @@ impl rustc_serialize::Encoder for Encoder {
{ {
self.emit_struct("foo", len, f) self.emit_struct("foo", len, f)
} }
fn emit_map_elt_key<F>(&mut self, _idx: usize, mut f: F) fn emit_map_elt_key<F>(&mut self, _idx: usize, f: F)
-> Result<(), Error> -> Result<(), Error>
where F: FnMut(&mut Encoder) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error>
{ {
match mem::replace(&mut self.state, NextMapKey) { match mem::replace(&mut self.state, NextMapKey) {
Start => {} Start => {}
@ -734,13 +735,7 @@ impl rustc_serialize::Decoder for Decoder {
} }
} }
impl fmt::Show for DecodeError { impl fmt::Display 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,16 +794,9 @@ impl StdError for DecodeError {
NilTooLong => "nonzero length string representing nil", NilTooLong => "nonzero length string representing nil",
} }
} }
fn detail(&self) -> Option<String> { Some(format!("{:?}", self)) }
} }
impl fmt::Show for Error { impl fmt::Display 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"),
@ -823,7 +811,6 @@ impl fmt::String for Error {
impl StdError for Error { impl StdError for Error {
fn description(&self) -> &str { "TOML encoding error" } fn description(&self) -> &str { "TOML encoding error" }
fn detail(&self) -> Option<String> { Some(format!("{:?}", self)) }
} }
#[cfg(test)] #[cfg(test)]
@ -854,7 +841,7 @@ mod tests {
#[test] #[test]
fn smoke() { fn smoke() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { a: isize } struct Foo { a: isize }
let v = Foo { a: 2 }; let v = Foo { a: 2 };
@ -864,7 +851,7 @@ mod tests {
#[test] #[test]
fn smoke_hyphen() { fn smoke_hyphen() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { a_b: isize } struct Foo { a_b: isize }
let v = Foo { a_b: 2 }; let v = Foo { a_b: 2 };
@ -878,9 +865,9 @@ mod tests {
#[test] #[test]
fn nested() { fn nested() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { a: isize, b: Bar } struct Foo { a: isize, b: Bar }
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Bar { a: String } struct Bar { a: String }
let v = Foo { a: 2, b: Bar { a: "test".to_string() } }; let v = Foo { a: 2, b: Bar { a: "test".to_string() } };
@ -896,7 +883,7 @@ mod tests {
#[test] #[test]
fn application_decode_error() { fn application_decode_error() {
#[derive(PartialEq, Show)] #[derive(PartialEq, Debug)]
struct Range10(usize); 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> {
@ -922,7 +909,7 @@ mod tests {
#[test] #[test]
fn array() { fn array() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { a: Vec<isize> } struct Foo { a: Vec<isize> }
let v = Foo { a: vec![1, 2, 3, 4] }; let v = Foo { a: vec![1, 2, 3, 4] };
@ -940,7 +927,7 @@ mod tests {
#[test] #[test]
fn tuple() { fn tuple() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { a: (isize, isize, isize, isize) } struct Foo { a: (isize, isize, isize, isize) }
let v = Foo { a: (1, 2, 3, 4) }; let v = Foo { a: (1, 2, 3, 4) };
@ -958,12 +945,12 @@ mod tests {
#[test] #[test]
fn inner_structs_with_options() { fn inner_structs_with_options() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { struct Foo {
a: Option<Box<Foo>>, a: Option<Box<Foo>>,
b: Bar, b: Bar,
} }
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Bar { struct Bar {
a: String, a: String,
b: f64, b: f64,
@ -994,7 +981,7 @@ mod tests {
#[test] #[test]
fn hashmap() { fn hashmap() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { struct Foo {
map: BTreeMap<String, isize>, map: BTreeMap<String, isize>,
set: HashSet<char>, set: HashSet<char>,
@ -1027,7 +1014,7 @@ mod tests {
#[test] #[test]
fn tuple_struct() { fn tuple_struct() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo(isize, 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);
@ -1044,9 +1031,9 @@ mod tests {
#[test] #[test]
fn table_array() { fn table_array() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { a: Vec<Bar>, } struct Foo { a: Vec<Bar>, }
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Bar { a: isize } 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 }] };
@ -1064,7 +1051,7 @@ mod tests {
#[test] #[test]
fn type_errors() { fn type_errors() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { bar: isize } struct Foo { bar: isize }
let mut d = Decoder::new(Table(map! { let mut d = Decoder::new(Table(map! {
@ -1074,7 +1061,7 @@ mod tests {
match a { match a {
Ok(..) => panic!("should not have decoded"), Ok(..) => panic!("should not have decoded"),
Err(e) => { Err(e) => {
assert_eq!(format!("{:?}", e).as_slice(), assert_eq!(format!("{}", e).as_slice(),
"expected a value of type `integer`, but \ "expected a value of type `integer`, but \
found a value of type `float` for the key `bar`"); found a value of type `float` for the key `bar`");
} }
@ -1083,7 +1070,7 @@ mod tests {
#[test] #[test]
fn missing_errors() { fn missing_errors() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { bar: isize } struct Foo { bar: isize }
let mut d = Decoder::new(Table(map! { let mut d = Decoder::new(Table(map! {
@ -1092,7 +1079,7 @@ mod tests {
match a { match a {
Ok(..) => panic!("should not have decoded"), Ok(..) => panic!("should not have decoded"),
Err(e) => { Err(e) => {
assert_eq!(format!("{:?}", e).as_slice(), assert_eq!(format!("{}", e).as_slice(),
"expected a value of type `integer` for the key `bar`"); "expected a value of type `integer` for the key `bar`");
} }
} }
@ -1100,15 +1087,15 @@ mod tests {
#[test] #[test]
fn parse_enum() { fn parse_enum() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { a: E } struct Foo { a: E }
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
enum E { enum E {
Bar(isize), Bar(isize),
Baz(f64), Baz(f64),
Last(Foo2), Last(Foo2),
} }
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo2 { struct Foo2 {
test: String, test: String,
} }
@ -1137,7 +1124,7 @@ mod tests {
#[test] #[test]
fn unused_fields() { fn unused_fields() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { a: isize } struct Foo { a: isize }
let v = Foo { a: 2 }; let v = Foo { a: 2 };
@ -1154,9 +1141,9 @@ mod tests {
#[test] #[test]
fn unused_fields2() { fn unused_fields2() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { a: Bar } struct Foo { a: Bar }
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Bar { a: isize } struct Bar { a: isize }
let v = Foo { a: Bar { a: 2 } }; let v = Foo { a: Bar { a: 2 } };
@ -1177,9 +1164,9 @@ mod tests {
#[test] #[test]
fn unused_fields3() { fn unused_fields3() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { a: Bar } struct Foo { a: Bar }
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Bar { a: isize } struct Bar { a: isize }
let v = Foo { a: Bar { a: 2 } }; let v = Foo { a: Bar { a: 2 } };
@ -1195,7 +1182,7 @@ mod tests {
#[test] #[test]
fn unused_fields4() { fn unused_fields4() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { a: BTreeMap<String, String> } struct Foo { a: BTreeMap<String, String> }
let v = Foo { a: map! { a, "foo".to_string() } }; let v = Foo { a: map! { a, "foo".to_string() } };
@ -1211,7 +1198,7 @@ mod tests {
#[test] #[test]
fn unused_fields5() { fn unused_fields5() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { a: Vec<String> } struct Foo { a: Vec<String> }
let v = Foo { a: vec!["a".to_string()] }; let v = Foo { a: vec!["a".to_string()] };
@ -1225,7 +1212,7 @@ mod tests {
#[test] #[test]
fn unused_fields6() { fn unused_fields6() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { a: Option<Vec<String>> } struct Foo { a: Option<Vec<String>> }
let v = Foo { a: Some(vec![]) }; let v = Foo { a: Some(vec![]) };
@ -1239,9 +1226,9 @@ mod tests {
#[test] #[test]
fn unused_fields7() { fn unused_fields7() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { a: Vec<Bar> } struct Foo { a: Vec<Bar> }
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Bar { a: isize } struct Bar { a: isize }
let v = Foo { a: vec![Bar { a: 1 }] }; let v = Foo { a: vec![Bar { a: 1 }] };
@ -1262,9 +1249,9 @@ mod tests {
#[test] #[test]
fn empty_arrays() { fn empty_arrays() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { a: Vec<Bar> } struct Foo { a: Vec<Bar> }
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Bar; struct Bar;
let v = Foo { a: vec![] }; let v = Foo { a: vec![] };
@ -1274,9 +1261,9 @@ mod tests {
#[test] #[test]
fn empty_arrays2() { fn empty_arrays2() {
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Foo { a: Option<Vec<Bar>> } struct Foo { a: Option<Vec<Bar>> }
#[derive(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Bar; struct Bar;
let v = Foo { a: None }; let v = Foo { a: None };

View file

@ -8,7 +8,7 @@ struct Printer<'a, 'b:'a> {
stack: Vec<&'a str>, stack: Vec<&'a str>,
} }
impl fmt::String for Value { impl fmt::Display for Value {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self { match *self {
String(ref s) => { String(ref s) => {