151
151
//!
152
152
//! ```rust
153
153
//! extern crate serialize;
154
- //! use std::collections::TreeMap ;
154
+ //! use std::collections::BTreeMap ;
155
155
//! use serialize::json::{mod, Json, ToJson};
156
156
//!
157
157
//! // Only generate `Decodable` trait implementation
165
165
//! // Specify encoding method manually
166
166
//! impl ToJson for TestStruct {
167
167
//! fn to_json(&self) -> Json {
168
- //! let mut d = TreeMap ::new();
168
+ //! let mut d = BTreeMap ::new();
169
169
//! // All standard types implement `to_json()`, so use it
170
170
//! d.insert("data_int".to_string(), self.data_int.to_json());
171
171
//! d.insert("data_str".to_string(), self.data_str.to_json());
@@ -198,7 +198,7 @@ use self::ParserState::*;
198
198
use self :: InternalStackElement :: * ;
199
199
200
200
use std;
201
- use std:: collections:: { HashMap , TreeMap } ;
201
+ use std:: collections:: { HashMap , BTreeMap } ;
202
202
use std:: { char, f64, fmt, io, num, str} ;
203
203
use std:: mem:: { swap, transmute} ;
204
204
use std:: num:: { Float , FPNaN , FPInfinite , Int } ;
@@ -223,7 +223,7 @@ pub enum Json {
223
223
}
224
224
225
225
pub type Array = Vec < Json > ;
226
- pub type Object = TreeMap < string:: String , Json > ;
226
+ pub type Object = BTreeMap < string:: String , Json > ;
227
227
228
228
/// The errors that can arise while parsing a JSON stream.
229
229
#[ deriving( Clone , PartialEq ) ]
@@ -973,7 +973,7 @@ impl Json {
973
973
self . as_object ( ) . is_some ( )
974
974
}
975
975
976
- /// If the Json value is an Object, returns the associated TreeMap .
976
+ /// If the Json value is an Object, returns the associated BTreeMap .
977
977
/// Returns None otherwise.
978
978
pub fn as_object < ' a > ( & ' a self ) -> Option < & ' a Object > {
979
979
match self {
@@ -1909,7 +1909,7 @@ impl<T: Iterator<char>> Builder<T> {
1909
1909
fn build_object ( & mut self ) -> Result < Json , BuilderError > {
1910
1910
self . bump ( ) ;
1911
1911
1912
- let mut values = TreeMap :: new ( ) ;
1912
+ let mut values = BTreeMap :: new ( ) ;
1913
1913
1914
1914
loop {
1915
1915
match self . token {
@@ -2391,9 +2391,9 @@ impl<A: ToJson> ToJson for Vec<A> {
2391
2391
fn to_json ( & self ) -> Json { Json :: Array ( self . iter ( ) . map ( |elt| elt. to_json ( ) ) . collect ( ) ) }
2392
2392
}
2393
2393
2394
- impl < A : ToJson > ToJson for TreeMap < string:: String , A > {
2394
+ impl < A : ToJson > ToJson for BTreeMap < string:: String , A > {
2395
2395
fn to_json ( & self ) -> Json {
2396
- let mut d = TreeMap :: new ( ) ;
2396
+ let mut d = BTreeMap :: new ( ) ;
2397
2397
for ( key, value) in self . iter ( ) {
2398
2398
d. insert ( ( * key) . clone ( ) , value. to_json ( ) ) ;
2399
2399
}
@@ -2403,7 +2403,7 @@ impl<A: ToJson> ToJson for TreeMap<string::String, A> {
2403
2403
2404
2404
impl < A : ToJson > ToJson for HashMap < string:: String , A > {
2405
2405
fn to_json ( & self ) -> Json {
2406
- let mut d = TreeMap :: new ( ) ;
2406
+ let mut d = BTreeMap :: new ( ) ;
2407
2407
for ( key, value) in self . iter ( ) {
2408
2408
d. insert ( ( * key) . clone ( ) , value. to_json ( ) ) ;
2409
2409
}
@@ -2451,7 +2451,7 @@ mod tests {
2451
2451
use super :: { PrettyEncoder , Json , from_str, DecodeResult , DecoderError , JsonEvent , Parser ,
2452
2452
StackElement , Stack , Encoder , Decoder } ;
2453
2453
use std:: { i64, u64, f32, f64, io} ;
2454
- use std:: collections:: TreeMap ;
2454
+ use std:: collections:: BTreeMap ;
2455
2455
use std:: num:: Float ;
2456
2456
use std:: string;
2457
2457
@@ -2501,7 +2501,7 @@ mod tests {
2501
2501
}
2502
2502
2503
2503
fn mk_object ( items : & [ ( string:: String , Json ) ] ) -> Json {
2504
- let mut d = TreeMap :: new ( ) ;
2504
+ let mut d = BTreeMap :: new ( ) ;
2505
2505
2506
2506
for item in items. iter ( ) {
2507
2507
match * item {
@@ -3075,7 +3075,7 @@ mod tests {
3075
3075
fn test_decode_map ( ) {
3076
3076
let s = "{\" a\" : \" Dog\" , \" b\" : {\" variant\" :\" Frog\" ,\
3077
3077
\" fields\" :[\" Henry\" , 349]}}";
3078
- let mut map: TreeMap < string:: String , Animal > = super :: decode ( s) . unwrap ( ) ;
3078
+ let mut map: BTreeMap < string:: String , Animal > = super :: decode ( s) . unwrap ( ) ;
3079
3079
3080
3080
assert_eq ! ( map. remove( & "a" . into_string( ) ) , Some ( Dog ) ) ;
3081
3081
assert_eq ! ( map. remove( & "b" . into_string( ) ) , Some ( Frog ( "Henry" . into_string( ) , 349 ) ) ) ;
@@ -3350,9 +3350,9 @@ mod tests {
3350
3350
#[ test]
3351
3351
fn test_prettyencoder_indent_level_param ( ) {
3352
3352
use std:: str:: from_utf8;
3353
- use std:: collections:: TreeMap ;
3353
+ use std:: collections:: BTreeMap ;
3354
3354
3355
- let mut tree = TreeMap :: new ( ) ;
3355
+ let mut tree = BTreeMap :: new ( ) ;
3356
3356
3357
3357
tree. insert ( "hello" . into_string ( ) , String ( "guten tag" . into_string ( ) ) ) ;
3358
3358
tree. insert ( "goodbye" . into_string ( ) , String ( "sayonara" . into_string ( ) ) ) ;
@@ -3719,13 +3719,13 @@ mod tests {
3719
3719
3720
3720
#[ test]
3721
3721
fn test_to_json ( ) {
3722
- use std:: collections:: { HashMap , TreeMap } ;
3722
+ use std:: collections:: { HashMap , BTreeMap } ;
3723
3723
use super :: ToJson ;
3724
3724
3725
3725
let array2 = Array ( vec ! ( U64 ( 1 ) , U64 ( 2 ) ) ) ;
3726
3726
let array3 = Array ( vec ! ( U64 ( 1 ) , U64 ( 2 ) , U64 ( 3 ) ) ) ;
3727
3727
let object = {
3728
- let mut tree_map = TreeMap :: new ( ) ;
3728
+ let mut tree_map = BTreeMap :: new ( ) ;
3729
3729
tree_map. insert ( "a" . into_string ( ) , U64 ( 1 ) ) ;
3730
3730
tree_map. insert ( "b" . into_string ( ) , U64 ( 2 ) ) ;
3731
3731
Object ( tree_map)
@@ -3758,7 +3758,7 @@ mod tests {
3758
3758
assert_eq ! ( ( & [ 1 u, 2 , 3 ] ) . to_json( ) , array3) ;
3759
3759
assert_eq ! ( ( vec![ 1 u, 2 ] ) . to_json( ) , array2) ;
3760
3760
assert_eq ! ( vec!( 1 u, 2 , 3 ) . to_json( ) , array3) ;
3761
- let mut tree_map = TreeMap :: new ( ) ;
3761
+ let mut tree_map = BTreeMap :: new ( ) ;
3762
3762
tree_map. insert ( "a" . into_string ( ) , 1 u) ;
3763
3763
tree_map. insert ( "b" . into_string ( ) , 2 ) ;
3764
3764
assert_eq ! ( tree_map. to_json( ) , object) ;
0 commit comments