@@ -29,7 +29,7 @@ use chrono::offset::TimeZone;
2929use oid;
3030use ordered:: OrderedDocument ;
3131use rustc_serialize:: hex:: { FromHex , ToHex } ;
32- use serde_json:: { self , Value } ;
32+ use serde_json:: Value ;
3333use spec:: { ElementType , BinarySubtype } ;
3434
3535/// Possible BSON value types.
@@ -269,13 +269,11 @@ impl Bson {
269269 /// Convert this value to the best approximate `Json`.
270270 pub fn to_json ( & self ) -> Value {
271271 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) ,
279277 & Bson :: Null => Value :: Null ,
280278 & Bson :: RegExp ( ref pat, ref opt) => json ! ( {
281279 "$regex" : pat,
@@ -312,12 +310,8 @@ impl Bson {
312310 "$numberLong" : ( v. timestamp( ) * 1000 ) + ( ( v. nanosecond( ) / 1000000 ) as i64 )
313311 }
314312 } ) ,
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} )
321315 }
322316 }
323317
@@ -327,9 +321,9 @@ impl Bson {
327321 & Value :: Number ( ref x) =>
328322 x. as_i64 ( ) . map ( Bson :: from)
329323 . 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 ( ) ,
333327 & Value :: Array ( ref x) => Bson :: Array ( x. iter ( ) . map ( Bson :: from_json) . collect ( ) ) ,
334328 & Value :: Object ( ref x) => {
335329 Bson :: from_extended_document ( x. iter ( )
0 commit comments