Update to rust master
This commit is contained in:
parent
1346affca9
commit
95c6161dce
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
|
|
||||||
name = "toml"
|
name = "toml"
|
||||||
version = "0.1.5"
|
version = "0.1.6"
|
||||||
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"
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
|
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
|
|
||||||
use std::collections::TreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::string;
|
use std::string;
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ pub enum Value {
|
||||||
pub type Array = Vec<Value>;
|
pub type Array = Vec<Value>;
|
||||||
|
|
||||||
/// Type representing a TOML table, payload of the Value::Table variant
|
/// Type representing a TOML table, payload of the Value::Table variant
|
||||||
pub type Table = TreeMap<string::String, Value>;
|
pub type Table = BTreeMap<string::String, Value>;
|
||||||
|
|
||||||
impl Value {
|
impl Value {
|
||||||
/// Tests whether this and another value have the same type.
|
/// Tests whether this and another value have the same type.
|
||||||
|
@ -185,9 +185,9 @@ impl Value {
|
||||||
for key in path.split('.') {
|
for key in path.split('.') {
|
||||||
match cur_value {
|
match cur_value {
|
||||||
&Value::Table(ref hm) => {
|
&Value::Table(ref hm) => {
|
||||||
match hm.find_with(|k| key.cmp(k.as_slice())) {
|
match hm.get(key) {
|
||||||
Some(v) => cur_value = v,
|
Some(v) => cur_value = v,
|
||||||
_ => return None
|
None => return None
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
&Value::Array(ref v) => {
|
&Value::Array(ref v) => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use std::char;
|
use std::char;
|
||||||
use std::collections::TreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::num::FromStrRadix;
|
use std::num::FromStrRadix;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
@ -140,7 +140,7 @@ impl<'a> Parser<'a> {
|
||||||
/// If an error occurs, the `errors` field of this parser can be consulted
|
/// If an error occurs, the `errors` field of this parser can be consulted
|
||||||
/// to determine the cause of the parse failure.
|
/// to determine the cause of the parse failure.
|
||||||
pub fn parse(&mut self) -> Option<TomlTable> {
|
pub fn parse(&mut self) -> Option<TomlTable> {
|
||||||
let mut ret = TreeMap::new();
|
let mut ret = BTreeMap::new();
|
||||||
loop {
|
loop {
|
||||||
self.ws();
|
self.ws();
|
||||||
match self.cur.clone().next() {
|
match self.cur.clone().next() {
|
||||||
|
@ -179,7 +179,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the section table
|
// Build the section table
|
||||||
let mut table = TreeMap::new();
|
let mut table = BTreeMap::new();
|
||||||
if !self.values(&mut table) { return None }
|
if !self.values(&mut table) { return None }
|
||||||
if array {
|
if array {
|
||||||
self.insert_array(&mut ret, section, Table(table), start)
|
self.insert_array(&mut ret, section, Table(table), start)
|
||||||
|
@ -677,7 +677,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize an empty table as part of this sub-key
|
// Initialize an empty table as part of this sub-key
|
||||||
tmp.insert(part.clone(), Table(TreeMap::new()));
|
tmp.insert(part.clone(), Table(BTreeMap::new()));
|
||||||
match *tmp.get_mut(&part).unwrap() {
|
match *tmp.get_mut(&part).unwrap() {
|
||||||
Table(ref mut inner) => cur = inner,
|
Table(ref mut inner) => cur = inner,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
@ -695,7 +695,7 @@ impl<'a> Parser<'a> {
|
||||||
let key = key.to_string();
|
let key = key.to_string();
|
||||||
let mut added = false;
|
let mut added = false;
|
||||||
if !into.contains_key(&key) {
|
if !into.contains_key(&key) {
|
||||||
into.insert(key.clone(), Table(TreeMap::new()));
|
into.insert(key.clone(), Table(BTreeMap::new()));
|
||||||
added = true;
|
added = true;
|
||||||
}
|
}
|
||||||
match into.get_mut(&key) {
|
match into.get_mut(&key) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::collections::TreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::error::Error as StdError;
|
use std::error::Error as StdError;
|
||||||
|
@ -136,7 +136,7 @@ pub fn encode_str<T: serialize::Encodable<Encoder, Error>>(t: &T) -> String {
|
||||||
impl Encoder {
|
impl Encoder {
|
||||||
/// Constructs a new encoder which will emit to the given output stream.
|
/// Constructs a new encoder which will emit to the given output stream.
|
||||||
pub fn new() -> Encoder {
|
pub fn new() -> Encoder {
|
||||||
Encoder { state: Start, toml: TreeMap::new() }
|
Encoder { state: Start, toml: BTreeMap::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_value(&mut self, v: Value) -> Result<(), Error> {
|
fn emit_value(&mut self, v: Value) -> Result<(), Error> {
|
||||||
|
@ -812,7 +812,7 @@ impl StdError for Error {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::{TreeMap, HashSet};
|
use std::collections::{BTreeMap, HashSet};
|
||||||
use serialize::{Encodable, Decodable};
|
use serialize::{Encodable, Decodable};
|
||||||
|
|
||||||
use super::{Encoder, Decoder, DecodeError};
|
use super::{Encoder, Decoder, DecodeError};
|
||||||
|
@ -831,7 +831,7 @@ mod tests {
|
||||||
}) );
|
}) );
|
||||||
|
|
||||||
macro_rules! map( ($($k:ident: $v:expr),*) => ({
|
macro_rules! map( ($($k:ident: $v:expr),*) => ({
|
||||||
let mut _m = TreeMap::new();
|
let mut _m = BTreeMap::new();
|
||||||
$(_m.insert(stringify!($k).to_string(), $v);)*
|
$(_m.insert(stringify!($k).to_string(), $v);)*
|
||||||
_m
|
_m
|
||||||
}) );
|
}) );
|
||||||
|
@ -855,7 +855,7 @@ mod tests {
|
||||||
assert_eq!(encode!(v), map! { a_b: Integer(2) });
|
assert_eq!(encode!(v), map! { a_b: Integer(2) });
|
||||||
assert_eq!(v, decode!(Table(encode!(v))));
|
assert_eq!(v, decode!(Table(encode!(v))));
|
||||||
|
|
||||||
let mut m = TreeMap::new();
|
let mut m = BTreeMap::new();
|
||||||
m.insert("a-b".to_string(), Integer(2));
|
m.insert("a-b".to_string(), Integer(2));
|
||||||
assert_eq!(v, decode!(Table(encode!(v))));
|
assert_eq!(v, decode!(Table(encode!(v))));
|
||||||
}
|
}
|
||||||
|
@ -980,13 +980,13 @@ mod tests {
|
||||||
fn hashmap() {
|
fn hashmap() {
|
||||||
#[deriving(Encodable, Decodable, PartialEq, Show)]
|
#[deriving(Encodable, Decodable, PartialEq, Show)]
|
||||||
struct Foo {
|
struct Foo {
|
||||||
map: TreeMap<String, int>,
|
map: BTreeMap<String, int>,
|
||||||
set: HashSet<char>,
|
set: HashSet<char>,
|
||||||
}
|
}
|
||||||
|
|
||||||
let v = Foo {
|
let v = Foo {
|
||||||
map: {
|
map: {
|
||||||
let mut m = TreeMap::new();
|
let mut m = BTreeMap::new();
|
||||||
m.insert("foo".to_string(), 10);
|
m.insert("foo".to_string(), 10);
|
||||||
m.insert("bar".to_string(), 4);
|
m.insert("bar".to_string(), 4);
|
||||||
m
|
m
|
||||||
|
@ -1180,7 +1180,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn unused_fields4() {
|
fn unused_fields4() {
|
||||||
#[deriving(Encodable, Decodable, PartialEq, Show)]
|
#[deriving(Encodable, Decodable, PartialEq, Show)]
|
||||||
struct Foo { a: TreeMap<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() } };
|
||||||
let mut d = Decoder::new(Table(map! {
|
let mut d = Decoder::new(Table(map! {
|
||||||
|
|
|
@ -96,10 +96,10 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||||
mod tests {
|
mod tests {
|
||||||
use Value;
|
use Value;
|
||||||
use Value::{String, Integer, Float, Boolean, Datetime, Array, Table};
|
use Value::{String, Integer, Float, Boolean, Datetime, Array, Table};
|
||||||
use std::collections::TreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
macro_rules! map( ($($k:expr: $v:expr),*) => ({
|
macro_rules! map( ($($k:expr: $v:expr),*) => ({
|
||||||
let mut _m = TreeMap::new();
|
let mut _m = BTreeMap::new();
|
||||||
$(_m.insert($k.to_string(), $v);)*
|
$(_m.insert($k.to_string(), $v);)*
|
||||||
_m
|
_m
|
||||||
}) );
|
}) );
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
|
|
||||||
use std::num::strconv;
|
use std::num::strconv;
|
||||||
use std::collections::TreeMap;
|
use std::collections::BTreeMap;
|
||||||
use self::serialize::json::{mod, Json};
|
use self::serialize::json::{mod, Json};
|
||||||
|
|
||||||
use {Parser, Value};
|
use {Parser, Value};
|
||||||
|
@ -9,7 +9,7 @@ use Value::{Table, Integer, Float, Boolean, Datetime, Array};
|
||||||
|
|
||||||
fn to_json(toml: Value) -> Json {
|
fn to_json(toml: Value) -> Json {
|
||||||
fn doit(s: &str, json: Json) -> Json {
|
fn doit(s: &str, json: Json) -> Json {
|
||||||
let mut map = TreeMap::new();
|
let mut map = BTreeMap::new();
|
||||||
map.insert("type".to_string(), Json::String(s.to_string()));
|
map.insert("type".to_string(), Json::String(s.to_string()));
|
||||||
map.insert("value".to_string(), json);
|
map.insert("value".to_string(), json);
|
||||||
Json::Object(map)
|
Json::Object(map)
|
||||||
|
|
Loading…
Reference in a new issue