Merge pull request #43 from vhbit/upd-deps

Updated serialize dependency
This commit is contained in:
Alex Crichton 2015-01-03 14:29:16 -06:00
commit a5863e764d
6 changed files with 46 additions and 44 deletions

View file

@ -16,4 +16,4 @@ facilitate deserializing and serializing Rust structures.
""" """
[dependencies] [dependencies]
rustc-serialize = "0.1.0" rustc-serialize = "0.2.0"

View file

@ -37,6 +37,7 @@
//! //!
#![feature(macro_rules)] #![feature(macro_rules)]
#![feature(old_orphan_check)]
#![deny(missing_docs)] #![deny(missing_docs)]
#![cfg_attr(test, deny(warnings))] #![cfg_attr(test, deny(warnings))]
@ -62,7 +63,7 @@ mod show;
mod serialization; mod serialization;
#[cfg(test)]mod test; #[cfg(test)]mod test;
/// Representation of a TOML value. /// Representation of a TOML value.
#[deriving(PartialEq, Clone)] #[derive(PartialEq, Clone)]
#[allow(missing_docs)] #[allow(missing_docs)]
pub enum Value { pub enum Value {
String(string::String), String(string::String),

View file

@ -5,7 +5,7 @@ use std::num::FromStrRadix;
use std::str; use std::str;
use Table as TomlTable; use Table as TomlTable;
use Value::{mod, Array, Table, Float, Integer, Boolean, Datetime}; use Value::{self, Array, Table, Float, Integer, Boolean, Datetime};
/// Parser for converting a string to a TOML `Value` instance. /// Parser for converting a string to a TOML `Value` instance.
/// ///
@ -27,7 +27,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.
#[deriving(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: uint,

View file

@ -23,6 +23,7 @@ use self::DecodeErrorKind::{ExpectedMapElement, NoEnumVariants, NilTooLong};
/// # Example /// # Example
/// ///
/// ``` /// ```
/// # #![feature(old_orphan_check)]
/// extern crate "rustc-serialize" as rustc_serialize; /// extern crate "rustc-serialize" as rustc_serialize;
/// extern crate toml; /// extern crate toml;
/// ///
@ -30,7 +31,7 @@ use self::DecodeErrorKind::{ExpectedMapElement, NoEnumVariants, NilTooLong};
/// use toml::{Encoder, Value}; /// use toml::{Encoder, Value};
/// use rustc_serialize::Encodable; /// use rustc_serialize::Encodable;
/// ///
/// #[deriving(RustcEncodable)] /// #[derive(RustcEncodable)]
/// struct MyStruct { foo: int, bar: String } /// struct MyStruct { foo: int, bar: String }
/// let my_struct = MyStruct { foo: 4, bar: "hello!".to_string() }; /// let my_struct = MyStruct { foo: 4, bar: "hello!".to_string() };
/// ///
@ -80,7 +81,7 @@ pub enum Error {
} }
/// Description for errors which can occur while decoding a type. /// Description for errors which can occur while decoding a type.
#[deriving(PartialEq)] #[derive(PartialEq)]
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>,
@ -89,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.
#[deriving(PartialEq)] #[derive(PartialEq)]
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),
@ -107,7 +108,7 @@ pub enum DecodeErrorKind {
NilTooLong NilTooLong
} }
#[deriving(PartialEq, Show)] #[derive(PartialEq, Show)]
enum EncoderState { enum EncoderState {
Start, Start,
NextKey(String), NextKey(String),
@ -838,7 +839,7 @@ mod tests {
#[test] #[test]
fn smoke() { fn smoke() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: int } struct Foo { a: int }
let v = Foo { a: 2 }; let v = Foo { a: 2 };
@ -848,7 +849,7 @@ mod tests {
#[test] #[test]
fn smoke_hyphen() { fn smoke_hyphen() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a_b: int } struct Foo { a_b: int }
let v = Foo { a_b: 2 }; let v = Foo { a_b: 2 };
@ -862,9 +863,9 @@ mod tests {
#[test] #[test]
fn nested() { fn nested() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: int, b: Bar } struct Foo { a: int, b: Bar }
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
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() } };
@ -880,7 +881,7 @@ mod tests {
#[test] #[test]
fn application_decode_error() { fn application_decode_error() {
#[deriving(PartialEq, Show)] #[derive(PartialEq, Show)]
struct Range10(uint); struct Range10(uint);
impl<D: ::rustc_serialize::Decoder<E>, E> Decodable<D, E> for Range10 { impl<D: ::rustc_serialize::Decoder<E>, E> Decodable<D, E> for Range10 {
fn decode(d: &mut D) -> Result<Range10, E> { fn decode(d: &mut D) -> Result<Range10, E> {
@ -906,7 +907,7 @@ mod tests {
#[test] #[test]
fn array() { fn array() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: Vec<int> } struct Foo { a: Vec<int> }
let v = Foo { a: vec![1, 2, 3, 4] }; let v = Foo { a: vec![1, 2, 3, 4] };
@ -924,7 +925,7 @@ mod tests {
#[test] #[test]
fn tuple() { fn tuple() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: (int, int, int, int) } struct Foo { a: (int, int, int, int) }
let v = Foo { a: (1, 2, 3, 4) }; let v = Foo { a: (1, 2, 3, 4) };
@ -942,12 +943,12 @@ mod tests {
#[test] #[test]
fn inner_structs_with_options() { fn inner_structs_with_options() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { struct Foo {
a: Option<Box<Foo>>, a: Option<Box<Foo>>,
b: Bar, b: Bar,
} }
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Bar { struct Bar {
a: String, a: String,
b: f64, b: f64,
@ -978,7 +979,7 @@ mod tests {
#[test] #[test]
fn hashmap() { fn hashmap() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { struct Foo {
map: BTreeMap<String, int>, map: BTreeMap<String, int>,
set: HashSet<char>, set: HashSet<char>,
@ -1011,7 +1012,7 @@ mod tests {
#[test] #[test]
fn tuple_struct() { fn tuple_struct() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo(int, String, f64); struct Foo(int, String, f64);
let v = Foo(1, "foo".to_string(), 4.5); let v = Foo(1, "foo".to_string(), 4.5);
@ -1028,9 +1029,9 @@ mod tests {
#[test] #[test]
fn table_array() { fn table_array() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: Vec<Bar>, } struct Foo { a: Vec<Bar>, }
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Bar { a: int } struct Bar { a: int }
let v = Foo { a: vec![Bar { a: 1 }, Bar { a: 2 }] }; let v = Foo { a: vec![Bar { a: 1 }, Bar { a: 2 }] };
@ -1048,7 +1049,7 @@ mod tests {
#[test] #[test]
fn type_errors() { fn type_errors() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { bar: int } struct Foo { bar: int }
let mut d = Decoder::new(Table(map! { let mut d = Decoder::new(Table(map! {
@ -1067,7 +1068,7 @@ mod tests {
#[test] #[test]
fn missing_errors() { fn missing_errors() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { bar: int } struct Foo { bar: int }
let mut d = Decoder::new(Table(map! { let mut d = Decoder::new(Table(map! {
@ -1084,15 +1085,15 @@ mod tests {
#[test] #[test]
fn parse_enum() { fn parse_enum() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: E } struct Foo { a: E }
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
enum E { enum E {
Bar(int), Bar(int),
Baz(f64), Baz(f64),
Last(Foo2), Last(Foo2),
} }
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo2 { struct Foo2 {
test: String, test: String,
} }
@ -1121,7 +1122,7 @@ mod tests {
#[test] #[test]
fn unused_fields() { fn unused_fields() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: int } struct Foo { a: int }
let v = Foo { a: 2 }; let v = Foo { a: 2 };
@ -1138,9 +1139,9 @@ mod tests {
#[test] #[test]
fn unused_fields2() { fn unused_fields2() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: Bar } struct Foo { a: Bar }
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Bar { a: int } struct Bar { a: int }
let v = Foo { a: Bar { a: 2 } }; let v = Foo { a: Bar { a: 2 } };
@ -1161,9 +1162,9 @@ mod tests {
#[test] #[test]
fn unused_fields3() { fn unused_fields3() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: Bar } struct Foo { a: Bar }
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Bar { a: int } struct Bar { a: int }
let v = Foo { a: Bar { a: 2 } }; let v = Foo { a: Bar { a: 2 } };
@ -1179,7 +1180,7 @@ mod tests {
#[test] #[test]
fn unused_fields4() { fn unused_fields4() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
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() } };
@ -1195,7 +1196,7 @@ mod tests {
#[test] #[test]
fn unused_fields5() { fn unused_fields5() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
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()] };
@ -1209,7 +1210,7 @@ mod tests {
#[test] #[test]
fn unused_fields6() { fn unused_fields6() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: Option<Vec<String>> } struct Foo { a: Option<Vec<String>> }
let v = Foo { a: Some(vec![]) }; let v = Foo { a: Some(vec![]) };
@ -1223,9 +1224,9 @@ mod tests {
#[test] #[test]
fn unused_fields7() { fn unused_fields7() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: Vec<Bar> } struct Foo { a: Vec<Bar> }
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Bar { a: int } struct Bar { a: int }
let v = Foo { a: vec![Bar { a: 1 }] }; let v = Foo { a: vec![Bar { a: 1 }] };
@ -1246,9 +1247,9 @@ mod tests {
#[test] #[test]
fn empty_arrays() { fn empty_arrays() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: Vec<Bar> } struct Foo { a: Vec<Bar> }
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Bar; struct Bar;
let v = Foo { a: vec![] }; let v = Foo { a: vec![] };
@ -1258,9 +1259,9 @@ mod tests {
#[test] #[test]
fn empty_arrays2() { fn empty_arrays2() {
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Foo { a: Option<Vec<Bar>> } struct Foo { a: Option<Vec<Bar>> }
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)] #[derive(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Bar; struct Bar;
let v = Foo { a: None }; let v = Foo { a: None };

View file

@ -1,7 +1,7 @@
use std::fmt; use std::fmt;
use Table as TomlTable; use Table as TomlTable;
use Value::{mod, 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> {
output: &'a mut fmt::Formatter<'b>, output: &'a mut fmt::Formatter<'b>,

View file

@ -2,7 +2,7 @@ extern crate serialize;
use std::num::strconv; use std::num::strconv;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use self::serialize::json::{mod, Json}; use self::serialize::json::{self, Json};
use {Parser, Value}; use {Parser, Value};
use Value::{Table, Integer, Float, Boolean, Datetime, Array}; use Value::{Table, Integer, Float, Boolean, Datetime, Array};
@ -57,8 +57,8 @@ fn run(toml: &str, json: &str) {
let toml_json = to_json(Table(table)); let toml_json = to_json(Table(table));
assert!(json == toml_json, assert!(json == toml_json,
"expected\n{}\ngot\n{}\n", "expected\n{}\ngot\n{}\n",
json.to_pretty_str(), json.pretty(),
toml_json.to_pretty_str()); toml_json.pretty());
} }
macro_rules! test( ($name:ident, $toml:expr, $json:expr) => ( macro_rules! test( ($name:ident, $toml:expr, $json:expr) => (