@@ -29,7 +29,7 @@ use chrono::offset::TimeZone;
29
29
use oid;
30
30
use ordered:: OrderedDocument ;
31
31
use rustc_serialize:: hex:: { FromHex , ToHex } ;
32
- use serde_json:: { self , Value } ;
32
+ use serde_json:: Value ;
33
33
use spec:: { ElementType , BinarySubtype } ;
34
34
35
35
/// Possible BSON value types.
@@ -269,13 +269,11 @@ impl Bson {
269
269
/// Convert this value to the best approximate `Json`.
270
270
pub fn to_json ( & self ) -> Value {
271
271
match self {
272
- & Bson :: FloatingPoint ( v) => v. into ( ) ,
273
- & Bson :: String ( ref v) => Value :: String ( v. clone ( ) ) ,
274
- & Bson :: Array ( ref v) =>
275
- Value :: Array ( v. iter ( ) . map ( |x| x. to_json ( ) ) . collect ( ) ) ,
276
- & Bson :: Document ( ref v) =>
277
- Value :: Object ( v. iter ( ) . map ( |( k, v) | ( k. clone ( ) , v. to_json ( ) ) ) . collect :: < serde_json:: Map < String , Value > > ( ) ) ,
278
- & Bson :: Boolean ( v) => Value :: Bool ( v) ,
272
+ & Bson :: FloatingPoint ( v) => json ! ( v) ,
273
+ & Bson :: String ( ref v) => json ! ( v) ,
274
+ & Bson :: Array ( ref v) => json ! ( v) ,
275
+ & Bson :: Document ( ref v) => json ! ( v) ,
276
+ & Bson :: Boolean ( v) => json ! ( v) ,
279
277
& Bson :: Null => Value :: Null ,
280
278
& Bson :: RegExp ( ref pat, ref opt) => json ! ( {
281
279
"$regex" : pat,
@@ -312,12 +310,8 @@ impl Bson {
312
310
"$numberLong" : ( v. timestamp( ) * 1000 ) + ( ( v. nanosecond( ) / 1000000 ) as i64 )
313
311
}
314
312
} ) ,
315
- & Bson :: Symbol ( ref v) => {
316
- // FIXME: Don't know what is the best way to encode Symbol type
317
- json ! ( {
318
- "$symbol" : v
319
- } )
320
- }
313
+ // FIXME: Don't know what is the best way to encode Symbol type
314
+ & Bson :: Symbol ( ref v) => json ! ( { "$symbol" : v} )
321
315
}
322
316
}
323
317
@@ -327,9 +321,9 @@ impl Bson {
327
321
& Value :: Number ( ref x) =>
328
322
x. as_i64 ( ) . map ( Bson :: from)
329
323
. or ( x. as_u64 ( ) . map ( Bson :: from) )
330
- . expect ( "blah" ) ,
331
- & Value :: String ( ref x) => Bson :: String ( x . clone ( ) ) ,
332
- & Value :: Bool ( x) => Bson :: Boolean ( x ) ,
324
+ . expect ( & format ! ( "Invalid number value: {}" , x ) ) ,
325
+ & Value :: String ( ref x) => x . into ( ) ,
326
+ & Value :: Bool ( x) => x . into ( ) ,
333
327
& Value :: Array ( ref x) => Bson :: Array ( x. iter ( ) . map ( Bson :: from_json) . collect ( ) ) ,
334
328
& Value :: Object ( ref x) => {
335
329
Bson :: from_extended_document ( x. iter ( )
0 commit comments