@@ -482,6 +482,45 @@ impl TryFrom<RawBson> for Bson {
482
482
}
483
483
}
484
484
485
+ impl TryFrom < Bson > for RawBson {
486
+ type Error = Error ;
487
+
488
+ fn try_from ( bson : Bson ) -> Result < RawBson > {
489
+ Ok ( match bson {
490
+ Bson :: Double ( d) => RawBson :: Double ( d) ,
491
+ Bson :: String ( s) => RawBson :: String ( s) ,
492
+ Bson :: Document ( doc) => RawBson :: Document ( ( & doc) . try_into ( ) ?) ,
493
+ Bson :: Array ( arr) => RawBson :: Array (
494
+ arr. into_iter ( )
495
+ . map ( |b| -> Result < RawBson > { b. try_into ( ) } )
496
+ . collect :: < Result < RawArrayBuf > > ( ) ?,
497
+ ) ,
498
+ Bson :: Binary ( bin) => RawBson :: Binary ( bin) ,
499
+ Bson :: ObjectId ( id) => RawBson :: ObjectId ( id) ,
500
+ Bson :: Boolean ( b) => RawBson :: Boolean ( b) ,
501
+ Bson :: DateTime ( dt) => RawBson :: DateTime ( dt) ,
502
+ Bson :: Null => RawBson :: Null ,
503
+ Bson :: RegularExpression ( regex) => RawBson :: RegularExpression ( regex) ,
504
+ Bson :: JavaScriptCode ( s) => RawBson :: JavaScriptCode ( s) ,
505
+ Bson :: Int32 ( i) => RawBson :: Int32 ( i) ,
506
+ Bson :: Timestamp ( ts) => RawBson :: Timestamp ( ts) ,
507
+ Bson :: Int64 ( i) => RawBson :: Int64 ( i) ,
508
+ Bson :: Undefined => RawBson :: Undefined ,
509
+ Bson :: DbPointer ( p) => RawBson :: DbPointer ( p) ,
510
+ Bson :: Symbol ( s) => RawBson :: Symbol ( s) ,
511
+ Bson :: JavaScriptCodeWithScope ( jcws) => {
512
+ RawBson :: JavaScriptCodeWithScope ( crate :: RawJavaScriptCodeWithScope {
513
+ code : jcws. code ,
514
+ scope : ( & jcws. scope ) . try_into ( ) ?,
515
+ } )
516
+ }
517
+ Bson :: Decimal128 ( d) => RawBson :: Decimal128 ( d) ,
518
+ Bson :: MaxKey => RawBson :: MaxKey ,
519
+ Bson :: MinKey => RawBson :: MinKey ,
520
+ } )
521
+ }
522
+ }
523
+
485
524
/// A BSON "code with scope" value backed by owned raw BSON.
486
525
#[ derive( Debug , Clone , PartialEq ) ]
487
526
pub struct RawJavaScriptCodeWithScope {
0 commit comments