@@ -87,71 +87,71 @@ impl Default for Bson {
8787
8888impl Debug for Bson {
8989 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
90- match self {
91- & Bson :: FloatingPoint ( p) => write ! ( f, "FloatingPoint({:?})" , p) ,
92- & Bson :: String ( ref s) => write ! ( f, "String({:?})" , s) ,
93- & Bson :: Array ( ref vec) => write ! ( f, "Array({:?})" , vec) ,
94- & Bson :: Document ( ref doc) => write ! ( f, "Document({:?})" , doc) ,
95- & Bson :: Boolean ( b) => write ! ( f, "Boolean({:?})" , b) ,
96- & Bson :: Null => write ! ( f, "Null" ) ,
97- & Bson :: RegExp ( ref pat, ref opt) => write ! ( f, "RegExp(/{:?}/{:?})" , pat, opt) ,
98- & Bson :: JavaScriptCode ( ref s) => write ! ( f, "JavaScriptCode({:?})" , s) ,
99- & Bson :: JavaScriptCodeWithScope ( ref s, ref scope) => {
90+ match * self {
91+ Bson :: FloatingPoint ( p) => write ! ( f, "FloatingPoint({:?})" , p) ,
92+ Bson :: String ( ref s) => write ! ( f, "String({:?})" , s) ,
93+ Bson :: Array ( ref vec) => write ! ( f, "Array({:?})" , vec) ,
94+ Bson :: Document ( ref doc) => write ! ( f, "Document({:?})" , doc) ,
95+ Bson :: Boolean ( b) => write ! ( f, "Boolean({:?})" , b) ,
96+ Bson :: Null => write ! ( f, "Null" ) ,
97+ Bson :: RegExp ( ref pat, ref opt) => write ! ( f, "RegExp(/{:?}/{:?})" , pat, opt) ,
98+ Bson :: JavaScriptCode ( ref s) => write ! ( f, "JavaScriptCode({:?})" , s) ,
99+ Bson :: JavaScriptCodeWithScope ( ref s, ref scope) => {
100100 write ! ( f, "JavaScriptCodeWithScope({:?}, {:?})" , s, scope)
101101 }
102- & Bson :: I32 ( v) => write ! ( f, "I32({:?})" , v) ,
103- & Bson :: I64 ( v) => write ! ( f, "I64({:?})" , v) ,
104- & Bson :: TimeStamp ( i) => {
102+ Bson :: I32 ( v) => write ! ( f, "I32({:?})" , v) ,
103+ Bson :: I64 ( v) => write ! ( f, "I64({:?})" , v) ,
104+ Bson :: TimeStamp ( i) => {
105105 let time = ( i >> 32 ) as i32 ;
106106 let inc = ( i & 0xFFFFFFFF ) as i32 ;
107107
108108 write ! ( f, "TimeStamp({}, {})" , time, inc)
109109 }
110- & Bson :: Binary ( t, ref vec) => write ! ( f, "BinData({}, 0x{})" , u8 :: from( t) , hex:: encode( vec) ) ,
111- & Bson :: ObjectId ( ref id) => write ! ( f, "ObjectId({:?})" , id) ,
112- & Bson :: UtcDatetime ( date_time) => write ! ( f, "UtcDatetime({:?})" , date_time) ,
113- & Bson :: Symbol ( ref sym) => write ! ( f, "Symbol({:?})" , sym) ,
110+ Bson :: Binary ( t, ref vec) => write ! ( f, "BinData({}, 0x{})" , u8 :: from( t) , hex:: encode( vec) ) ,
111+ Bson :: ObjectId ( ref id) => write ! ( f, "ObjectId({:?})" , id) ,
112+ Bson :: UtcDatetime ( date_time) => write ! ( f, "UtcDatetime({:?})" , date_time) ,
113+ Bson :: Symbol ( ref sym) => write ! ( f, "Symbol({:?})" , sym) ,
114114 }
115115 }
116116}
117117
118118impl Display for Bson {
119119 fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
120- match self {
121- & Bson :: FloatingPoint ( f) => write ! ( fmt, "{}" , f) ,
122- & Bson :: String ( ref s) => write ! ( fmt, "\" {}\" " , s) ,
123- & Bson :: Array ( ref vec) => {
124- write ! ( fmt, "[" ) ?;
120+ match * self {
121+ Bson :: FloatingPoint ( f) => write ! ( fmt, "{}" , f) ,
122+ Bson :: String ( ref s) => write ! ( fmt, "\" {}\" " , s) ,
123+ Bson :: Array ( ref vec) => {
124+ fmt. write_str ( "[" ) ?;
125125
126126 let mut first = true ;
127- for bson in vec. iter ( ) {
127+ for bson in vec {
128128 if !first {
129- write ! ( fmt, ", " ) ?;
129+ fmt. write_str ( ", " ) ?;
130130 }
131131
132132 write ! ( fmt, "{}" , bson) ?;
133133 first = false ;
134134 }
135135
136- write ! ( fmt, "]" )
136+ fmt. write_str ( "]" )
137137 }
138- & Bson :: Document ( ref doc) => write ! ( fmt, "{}" , doc) ,
139- & Bson :: Boolean ( b) => write ! ( fmt, "{}" , b) ,
140- & Bson :: Null => write ! ( fmt, "null" ) ,
141- & Bson :: RegExp ( ref pat, ref opt) => write ! ( fmt, "/{}/{}" , pat, opt) ,
142- & Bson :: JavaScriptCode ( ref s) | & Bson :: JavaScriptCodeWithScope ( ref s, _) => fmt. write_str ( & s) ,
143- & Bson :: I32 ( i) => write ! ( fmt, "{}" , i) ,
144- & Bson :: I64 ( i) => write ! ( fmt, "{}" , i) ,
145- & Bson :: TimeStamp ( i) => {
138+ Bson :: Document ( ref doc) => write ! ( fmt, "{}" , doc) ,
139+ Bson :: Boolean ( b) => write ! ( fmt, "{}" , b) ,
140+ Bson :: Null => write ! ( fmt, "null" ) ,
141+ Bson :: RegExp ( ref pat, ref opt) => write ! ( fmt, "/{}/{}" , pat, opt) ,
142+ Bson :: JavaScriptCode ( ref s) | Bson :: JavaScriptCodeWithScope ( ref s, _) => fmt. write_str ( & s) ,
143+ Bson :: I32 ( i) => write ! ( fmt, "{}" , i) ,
144+ Bson :: I64 ( i) => write ! ( fmt, "{}" , i) ,
145+ Bson :: TimeStamp ( i) => {
146146 let time = ( i >> 32 ) as i32 ;
147147 let inc = ( i & 0xFFFFFFFF ) as i32 ;
148148
149149 write ! ( fmt, "Timestamp({}, {})" , time, inc)
150150 }
151- & Bson :: Binary ( t, ref vec) => write ! ( fmt, "BinData({}, 0x{})" , u8 :: from( t) , hex:: encode( vec) ) ,
152- & Bson :: ObjectId ( ref id) => write ! ( fmt, "ObjectId(\" {}\" )" , id) ,
153- & Bson :: UtcDatetime ( date_time) => write ! ( fmt, "Date(\" {}\" )" , date_time) ,
154- & Bson :: Symbol ( ref sym) => write ! ( fmt, "Symbol(\" {}\" )" , sym) ,
151+ Bson :: Binary ( t, ref vec) => write ! ( fmt, "BinData({}, 0x{})" , u8 :: from( t) , hex:: encode( vec) ) ,
152+ Bson :: ObjectId ( ref id) => write ! ( fmt, "ObjectId(\" {}\" )" , id) ,
153+ Bson :: UtcDatetime ( date_time) => write ! ( fmt, "Date(\" {}\" )" , date_time) ,
154+ Bson :: Symbol ( ref sym) => write ! ( fmt, "Symbol(\" {}\" )" , sym) ,
155155 }
156156 }
157157}
@@ -205,23 +205,20 @@ impl From<bool> for Bson {
205205}
206206
207207impl From < ( String , String ) > for Bson {
208- fn from ( a : ( String , String ) ) -> Bson {
209- let ( a1, a2) = a;
210- Bson :: RegExp ( a1. to_owned ( ) , a2. to_owned ( ) )
208+ fn from ( ( pat, opt) : ( String , String ) ) -> Bson {
209+ Bson :: RegExp ( pat, opt)
211210 }
212211}
213212
214213impl From < ( String , Document ) > for Bson {
215- fn from ( a : ( String , Document ) ) -> Bson {
216- let ( a1, a2) = a;
217- Bson :: JavaScriptCodeWithScope ( a1, a2)
214+ fn from ( ( code, scope) : ( String , Document ) ) -> Bson {
215+ Bson :: JavaScriptCodeWithScope ( code, scope)
218216 }
219217}
220218
221219impl From < ( BinarySubtype , Vec < u8 > ) > for Bson {
222- fn from ( a : ( BinarySubtype , Vec < u8 > ) ) -> Bson {
223- let ( a1, a2) = a;
224- Bson :: Binary ( a1, a2)
220+ fn from ( ( ty, data) : ( BinarySubtype , Vec < u8 > ) ) -> Bson {
221+ Bson :: Binary ( ty, data)
225222 }
226223}
227224
@@ -257,7 +254,7 @@ impl From<[u8; 12]> for Bson {
257254
258255impl From < oid:: ObjectId > for Bson {
259256 fn from ( a : oid:: ObjectId ) -> Bson {
260- Bson :: ObjectId ( a. to_owned ( ) )
257+ Bson :: ObjectId ( a)
261258 }
262259}
263260
@@ -279,16 +276,16 @@ impl From<Value> for Bson {
279276 Value :: Bool ( x) => x. into ( ) ,
280277 Value :: Array ( x) => Bson :: Array ( x. into_iter ( ) . map ( Bson :: from) . collect ( ) ) ,
281278 Value :: Object ( x) => {
282- Bson :: from_extended_document ( x. into_iter ( ) . map ( |( k, v) | ( k. clone ( ) , v. into ( ) ) ) . collect ( ) )
279+ Bson :: from_extended_document ( x. into_iter ( ) . map ( |( k, v) | ( k, v. into ( ) ) ) . collect ( ) )
283280 }
284281 Value :: Null => Bson :: Null ,
285282 }
286283 }
287284}
288285
289- impl Into < Value > for Bson {
290- fn into ( self ) -> Value {
291- match self {
286+ impl From < Bson > for Value {
287+ fn from ( bson : Bson ) -> Self {
288+ match bson {
292289 Bson :: FloatingPoint ( v) => json ! ( v) ,
293290 Bson :: String ( v) => json ! ( v) ,
294291 Bson :: Array ( v) => json ! ( v) ,
@@ -336,23 +333,23 @@ impl Into<Value> for Bson {
336333impl Bson {
337334 /// Get the `ElementType` of this value.
338335 pub fn element_type ( & self ) -> ElementType {
339- match self {
340- & Bson :: FloatingPoint ( ..) => ElementType :: FloatingPoint ,
341- & Bson :: String ( ..) => ElementType :: Utf8String ,
342- & Bson :: Array ( ..) => ElementType :: Array ,
343- & Bson :: Document ( ..) => ElementType :: EmbeddedDocument ,
344- & Bson :: Boolean ( ..) => ElementType :: Boolean ,
345- & Bson :: Null => ElementType :: NullValue ,
346- & Bson :: RegExp ( ..) => ElementType :: RegularExpression ,
347- & Bson :: JavaScriptCode ( ..) => ElementType :: JavaScriptCode ,
348- & Bson :: JavaScriptCodeWithScope ( ..) => ElementType :: JavaScriptCodeWithScope ,
349- & Bson :: I32 ( ..) => ElementType :: Integer32Bit ,
350- & Bson :: I64 ( ..) => ElementType :: Integer64Bit ,
351- & Bson :: TimeStamp ( ..) => ElementType :: TimeStamp ,
352- & Bson :: Binary ( ..) => ElementType :: Binary ,
353- & Bson :: ObjectId ( ..) => ElementType :: ObjectId ,
354- & Bson :: UtcDatetime ( ..) => ElementType :: UtcDatetime ,
355- & Bson :: Symbol ( ..) => ElementType :: Symbol ,
336+ match * self {
337+ Bson :: FloatingPoint ( ..) => ElementType :: FloatingPoint ,
338+ Bson :: String ( ..) => ElementType :: Utf8String ,
339+ Bson :: Array ( ..) => ElementType :: Array ,
340+ Bson :: Document ( ..) => ElementType :: EmbeddedDocument ,
341+ Bson :: Boolean ( ..) => ElementType :: Boolean ,
342+ Bson :: Null => ElementType :: NullValue ,
343+ Bson :: RegExp ( ..) => ElementType :: RegularExpression ,
344+ Bson :: JavaScriptCode ( ..) => ElementType :: JavaScriptCode ,
345+ Bson :: JavaScriptCodeWithScope ( ..) => ElementType :: JavaScriptCodeWithScope ,
346+ Bson :: I32 ( ..) => ElementType :: Integer32Bit ,
347+ Bson :: I64 ( ..) => ElementType :: Integer64Bit ,
348+ Bson :: TimeStamp ( ..) => ElementType :: TimeStamp ,
349+ Bson :: Binary ( ..) => ElementType :: Binary ,
350+ Bson :: ObjectId ( ..) => ElementType :: ObjectId ,
351+ Bson :: UtcDatetime ( ..) => ElementType :: UtcDatetime ,
352+ Bson :: Symbol ( ..) => ElementType :: Symbol ,
356353 }
357354 }
358355
@@ -437,7 +434,7 @@ impl Bson {
437434 }
438435
439436 /// Converts from extended format.
440- /// This function mainly used for [extended JSON format](https://docs.mongodb.com/manual/reference/mongodb-extended-json/).
437+ /// This function is mainly used for [extended JSON format](https://docs.mongodb.com/manual/reference/mongodb-extended-json/).
441438 #[ doc( hidden) ]
442439 pub fn from_extended_document ( values : Document ) -> Bson {
443440 if values. len ( ) == 2 {
@@ -478,7 +475,7 @@ impl Bson {
478475 /// If `Bson` is `FloatingPoint`, return its value. Returns `None` otherwise
479476 pub fn as_f64 ( & self ) -> Option < f64 > {
480477 match * self {
481- Bson :: FloatingPoint ( ref v) => Some ( * v) ,
478+ Bson :: FloatingPoint ( v) => Some ( v) ,
482479 _ => None ,
483480 }
484481 }
@@ -510,23 +507,23 @@ impl Bson {
510507 /// If `Bson` is `Boolean`, return its value. Returns `None` otherwise
511508 pub fn as_bool ( & self ) -> Option < bool > {
512509 match * self {
513- Bson :: Boolean ( ref v) => Some ( * v) ,
510+ Bson :: Boolean ( v) => Some ( v) ,
514511 _ => None ,
515512 }
516513 }
517514
518515 /// If `Bson` is `I32`, return its value. Returns `None` otherwise
519516 pub fn as_i32 ( & self ) -> Option < i32 > {
520517 match * self {
521- Bson :: I32 ( ref v) => Some ( * v) ,
518+ Bson :: I32 ( v) => Some ( v) ,
522519 _ => None ,
523520 }
524521 }
525522
526523 /// If `Bson` is `I64`, return its value. Returns `None` otherwise
527524 pub fn as_i64 ( & self ) -> Option < i64 > {
528525 match * self {
529- Bson :: I64 ( ref v) => Some ( * v) ,
526+ Bson :: I64 ( v) => Some ( v) ,
530527 _ => None ,
531528 }
532529 }
@@ -558,7 +555,7 @@ impl Bson {
558555 /// If `Bson` is `TimeStamp`, return its value. Returns `None` otherwise
559556 pub fn as_timestamp ( & self ) -> Option < i64 > {
560557 match * self {
561- Bson :: TimeStamp ( ref v) => Some ( * v) ,
558+ Bson :: TimeStamp ( v) => Some ( v) ,
562559 _ => None ,
563560 }
564561 }
@@ -587,7 +584,7 @@ impl Bson {
587584/// timestamp: TimeStamp,
588585/// }
589586/// ```
590- #[ derive( Debug , Eq , PartialEq , Clone ) ]
587+ #[ derive( Debug , Eq , PartialEq , Clone , Copy , Hash ) ]
591588pub struct TimeStamp {
592589 pub t : u32 ,
593590 pub i : u32 ,
0 commit comments