22
22
//! BSON definition
23
23
24
24
use std:: collections:: BTreeMap ;
25
- use std:: string;
26
25
27
26
use chrono:: { DateTime , UTC } ;
28
27
use rustc_serialize:: json;
@@ -34,13 +33,13 @@ use spec::BinarySubtype;
34
33
pub enum Bson {
35
34
FloatingPoint ( f64 ) ,
36
35
String ( String ) ,
37
- Array ( self :: Array ) ,
38
- Document ( self :: Document ) ,
36
+ Array ( Array ) ,
37
+ Document ( Document ) ,
39
38
Boolean ( bool ) ,
40
39
Null ,
41
- RegExp ( string :: String , string :: String ) ,
42
- JavaScriptCode ( string :: String ) ,
43
- JavaScriptCodeWithScope ( string :: String , self :: Document ) ,
40
+ RegExp ( String , String ) ,
41
+ JavaScriptCode ( String ) ,
42
+ JavaScriptCodeWithScope ( String , Document ) ,
44
43
Deprecated ,
45
44
I32 ( i32 ) ,
46
45
I64 ( i64 ) ,
@@ -66,32 +65,32 @@ impl Bson {
66
65
& Bson :: Null => json:: Json :: Null ,
67
66
& Bson :: RegExp ( ref pat, ref opt) => {
68
67
let mut re = json:: Object :: new ( ) ;
69
- re. insert ( "pattern" . to_string ( ) , json:: Json :: String ( pat. clone ( ) ) ) ;
70
- re. insert ( "options" . to_string ( ) , json:: Json :: String ( opt. clone ( ) ) ) ;
68
+ re. insert ( "pattern" . to_owned ( ) , json:: Json :: String ( pat. clone ( ) ) ) ;
69
+ re. insert ( "options" . to_owned ( ) , json:: Json :: String ( opt. clone ( ) ) ) ;
71
70
72
71
json:: Json :: Object ( re)
73
72
} ,
74
73
& Bson :: JavaScriptCode ( ref code) => json:: Json :: String ( code. clone ( ) ) ,
75
74
& Bson :: JavaScriptCodeWithScope ( ref code, ref scope) => {
76
75
let mut obj = json:: Object :: new ( ) ;
77
- obj. insert ( "code" . to_string ( ) , json:: Json :: String ( code. clone ( ) ) ) ;
76
+ obj. insert ( "code" . to_owned ( ) , json:: Json :: String ( code. clone ( ) ) ) ;
78
77
79
78
let scope_obj =
80
79
scope. iter ( ) . map ( |( k, v) | ( k. clone ( ) , v. to_json ( ) ) ) . collect ( ) ;
81
80
82
- obj. insert ( "scope" . to_string ( ) , json:: Json :: Object ( scope_obj) ) ;
81
+ obj. insert ( "scope" . to_owned ( ) , json:: Json :: Object ( scope_obj) ) ;
83
82
84
83
json:: Json :: Object ( obj)
85
84
} ,
86
- & Bson :: Deprecated => json:: Json :: String ( "deprecated" . to_string ( ) ) ,
85
+ & Bson :: Deprecated => json:: Json :: String ( "deprecated" . to_owned ( ) ) ,
87
86
& Bson :: I32 ( v) => json:: Json :: I64 ( v as i64 ) ,
88
87
& Bson :: I64 ( v) => json:: Json :: I64 ( v) ,
89
88
& Bson :: TimeStamp ( v) => json:: Json :: I64 ( v) ,
90
89
& Bson :: Binary ( t, ref v) => {
91
90
let mut obj = json:: Object :: new ( ) ;
92
91
let tval: u8 = From :: from ( t) ;
93
- obj. insert ( "type" . to_string ( ) , json:: Json :: I64 ( tval as i64 ) ) ;
94
- obj. insert ( "data" . to_string ( ) , json:: Json :: String ( v[ ..] . to_hex ( ) ) ) ;
92
+ obj. insert ( "type" . to_owned ( ) , json:: Json :: I64 ( tval as i64 ) ) ;
93
+ obj. insert ( "data" . to_owned ( ) , json:: Json :: String ( v[ ..] . to_hex ( ) ) ) ;
95
94
96
95
json:: Json :: Object ( obj)
97
96
} ,
@@ -107,7 +106,7 @@ impl Bson {
107
106
& json:: Json :: F64 ( x) => Bson :: FloatingPoint ( x) ,
108
107
& json:: Json :: String ( ref x) => Bson :: String ( x. clone ( ) ) ,
109
108
& json:: Json :: Boolean ( x) => Bson :: Boolean ( x) ,
110
- & json:: Json :: Array ( ref x) => Bson :: Array ( x. iter ( ) . map ( |x| Bson :: from_json ( x ) ) . collect ( ) ) ,
109
+ & json:: Json :: Array ( ref x) => Bson :: Array ( x. iter ( ) . map ( Bson :: from_json) . collect ( ) ) ,
111
110
& json:: Json :: Object ( ref x) => Bson :: Document ( x. iter ( ) . map ( |( k, v) | ( k. clone ( ) , Bson :: from_json ( v) ) ) . collect ( ) ) ,
112
111
& json:: Json :: Null => Bson :: Null ,
113
112
}
@@ -120,7 +119,7 @@ pub trait ToBson {
120
119
121
120
impl ToBson for str {
122
121
fn to_bson ( & self ) -> Bson {
123
- Bson :: String ( self . to_string ( ) )
122
+ Bson :: String ( self . to_owned ( ) )
124
123
}
125
124
}
126
125
0 commit comments