mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 06:41:03 +00:00
Replace TreeMap/TreeSet with BTreeMap/BTreeSet in serde
Follow rust std changes: https://github.com/rust-lang/rfcs/blob/master/text/0509-collections-reform-part-2.md
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use std::collections::{HashMap, HashSet, TreeMap, TreeSet};
|
use std::collections::{HashMap, HashSet, BTreeMap, BTreeSet};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::num;
|
use std::num;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
@@ -770,9 +770,9 @@ impl<
|
|||||||
E,
|
E,
|
||||||
K: Deserialize<D, E> + Ord,
|
K: Deserialize<D, E> + Ord,
|
||||||
V: Deserialize<D, E>
|
V: Deserialize<D, E>
|
||||||
> Deserialize<D, E> for TreeMap<K, V> {
|
> Deserialize<D, E> for BTreeMap<K, V> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deserialize_token(d: &mut D, token: Token) -> Result<TreeMap<K, V>, E> {
|
fn deserialize_token(d: &mut D, token: Token) -> Result<BTreeMap<K, V>, E> {
|
||||||
d.expect_map(token)
|
d.expect_map(token)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -794,9 +794,9 @@ impl<
|
|||||||
D: Deserializer<E>,
|
D: Deserializer<E>,
|
||||||
E,
|
E,
|
||||||
T: Deserialize<D, E> + Ord
|
T: Deserialize<D, E> + Ord
|
||||||
> Deserialize<D, E> for TreeSet<T> {
|
> Deserialize<D, E> for BTreeSet<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deserialize_token(d: &mut D, token: Token) -> Result<TreeSet<T>, E> {
|
fn deserialize_token(d: &mut D, token: Token) -> Result<BTreeSet<T>, E> {
|
||||||
d.expect_seq(token)
|
d.expect_seq(token)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -8,7 +8,7 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use std::collections::TreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::str::StrAllocating;
|
use std::str::StrAllocating;
|
||||||
|
|
||||||
use json::value::{ToJson, Value};
|
use json::value::{ToJson, Value};
|
||||||
@@ -44,12 +44,12 @@ impl ArrayBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct ObjectBuilder {
|
pub struct ObjectBuilder {
|
||||||
object: TreeMap<String, Value>,
|
object: BTreeMap<String, Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectBuilder {
|
impl ObjectBuilder {
|
||||||
pub fn new() -> ObjectBuilder {
|
pub fn new() -> ObjectBuilder {
|
||||||
ObjectBuilder { object: TreeMap::new() }
|
ObjectBuilder { object: BTreeMap::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unwrap(self) -> Value {
|
pub fn unwrap(self) -> Value {
|
||||||
|
|||||||
+8
-8
@@ -1,4 +1,4 @@
|
|||||||
use std::collections::{HashMap, TreeMap, tree_map};
|
use std::collections::{HashMap, BTreeMap, btree_map};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io::{ByRefWriter, IoResult};
|
use std::io::{ByRefWriter, IoResult};
|
||||||
use std::io;
|
use std::io;
|
||||||
@@ -21,7 +21,7 @@ pub enum Value {
|
|||||||
Floating(f64),
|
Floating(f64),
|
||||||
String(String),
|
String(String),
|
||||||
Array(Vec<Value>),
|
Array(Vec<Value>),
|
||||||
Object(TreeMap<String, Value>),
|
Object(BTreeMap<String, Value>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Value {
|
impl Value {
|
||||||
@@ -99,7 +99,7 @@ impl Value {
|
|||||||
|
|
||||||
/// If the Json value is an Object, returns the associated TreeMap.
|
/// If the Json value is an Object, returns the associated TreeMap.
|
||||||
/// Returns None otherwise.
|
/// Returns None otherwise.
|
||||||
pub fn as_object<'a>(&'a self) -> Option<&'a TreeMap<String, Value>> {
|
pub fn as_object<'a>(&'a self) -> Option<&'a BTreeMap<String, Value>> {
|
||||||
match *self {
|
match *self {
|
||||||
Value::Object(ref map) => Some(map),
|
Value::Object(ref map) => Some(map),
|
||||||
_ => None
|
_ => None
|
||||||
@@ -286,7 +286,7 @@ impl<D: de::Deserializer<E>, E> de::Deserialize<D, E> for Value {
|
|||||||
Token::EnumStart(_, name, len) => {
|
Token::EnumStart(_, name, len) => {
|
||||||
let token = Token::SeqStart(len);
|
let token = Token::SeqStart(len);
|
||||||
let fields: Vec<Value> = try!(de::Deserialize::deserialize_token(d, token));
|
let fields: Vec<Value> = try!(de::Deserialize::deserialize_token(d, token));
|
||||||
let mut object = TreeMap::new();
|
let mut object = BTreeMap::new();
|
||||||
object.insert(name.to_string(), Value::Array(fields));
|
object.insert(name.to_string(), Value::Array(fields));
|
||||||
Ok(Value::Object(object))
|
Ok(Value::Object(object))
|
||||||
}
|
}
|
||||||
@@ -303,7 +303,7 @@ impl<D: de::Deserializer<E>, E> de::Deserialize<D, E> for Value {
|
|||||||
enum State {
|
enum State {
|
||||||
Value(Value),
|
Value(Value),
|
||||||
Array(vec::MoveItems<Value>),
|
Array(vec::MoveItems<Value>),
|
||||||
Object(tree_map::MoveEntries<String, Value>),
|
Object(btree_map::MoveEntries<String, Value>),
|
||||||
End,
|
End,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -627,9 +627,9 @@ impl<A:ToJson> ToJson for Vec<A> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A:ToJson> ToJson for TreeMap<String, A> {
|
impl<A:ToJson> ToJson for BTreeMap<String, A> {
|
||||||
fn to_json(&self) -> Value {
|
fn to_json(&self) -> Value {
|
||||||
let mut d = TreeMap::new();
|
let mut d = BTreeMap::new();
|
||||||
for (key, value) in self.iter() {
|
for (key, value) in self.iter() {
|
||||||
d.insert((*key).clone(), value.to_json());
|
d.insert((*key).clone(), value.to_json());
|
||||||
}
|
}
|
||||||
@@ -639,7 +639,7 @@ impl<A:ToJson> ToJson for TreeMap<String, A> {
|
|||||||
|
|
||||||
impl<A:ToJson> ToJson for HashMap<String, A> {
|
impl<A:ToJson> ToJson for HashMap<String, A> {
|
||||||
fn to_json(&self) -> Value {
|
fn to_json(&self) -> Value {
|
||||||
let mut d = TreeMap::new();
|
let mut d = BTreeMap::new();
|
||||||
for (key, value) in self.iter() {
|
for (key, value) in self.iter() {
|
||||||
d.insert((*key).clone(), value.to_json());
|
d.insert((*key).clone(), value.to_json());
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -8,7 +8,7 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use std::collections::{HashMap, HashSet, TreeMap, TreeSet};
|
use std::collections::{HashMap, HashSet, BTreeMap, BTreeSet};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -239,7 +239,7 @@ impl<
|
|||||||
E,
|
E,
|
||||||
K: Serialize<S, E> + Ord,
|
K: Serialize<S, E> + Ord,
|
||||||
V: Serialize<S, E>
|
V: Serialize<S, E>
|
||||||
> Serialize<S, E> for TreeMap<K, V> {
|
> Serialize<S, E> for BTreeMap<K, V> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn serialize(&self, s: &mut S) -> Result<(), E> {
|
fn serialize(&self, s: &mut S) -> Result<(), E> {
|
||||||
s.serialize_map(self.iter())
|
s.serialize_map(self.iter())
|
||||||
@@ -263,7 +263,7 @@ impl<
|
|||||||
S: Serializer<E>,
|
S: Serializer<E>,
|
||||||
E,
|
E,
|
||||||
T: Serialize<S, E> + Ord
|
T: Serialize<S, E> + Ord
|
||||||
> Serialize<S, E> for TreeSet<T> {
|
> Serialize<S, E> for BTreeSet<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn serialize(&self, s: &mut S) -> Result<(), E> {
|
fn serialize(&self, s: &mut S) -> Result<(), E> {
|
||||||
s.serialize_seq(self.iter())
|
s.serialize_seq(self.iter())
|
||||||
|
|||||||
Reference in New Issue
Block a user