@@ -29,14 +29,6 @@ use bson::{
29
29
DeserializerOptions ,
30
30
Document ,
31
31
JavaScriptCodeWithScope ,
32
- RawArray ,
33
- RawBinary ,
34
- RawBson ,
35
- RawDbPointer ,
36
- RawDocument ,
37
- RawDocumentBuf ,
38
- RawJavaScriptCodeWithScope ,
39
- RawRegex ,
40
32
Regex ,
41
33
SerializerOptions ,
42
34
Timestamp ,
@@ -145,18 +137,6 @@ where
145
137
) ;
146
138
}
147
139
148
- /// Verifies the following:
149
- /// - Deserializing a `T` from the provided bytes does not error
150
- /// - Serializing the `T` back to bytes produces the input.
151
- fn run_raw_round_trip_test < ' de , T > ( bytes : & ' de [ u8 ] , description : & str )
152
- where
153
- T : Deserialize < ' de > + Serialize + std:: fmt:: Debug ,
154
- {
155
- let t: T = bson:: from_slice ( bytes) . expect ( description) ;
156
- let vec = bson:: to_vec ( & t) . expect ( description) ;
157
- assert_eq ! ( vec. as_slice( ) , bytes) ;
158
- }
159
-
160
140
#[ test]
161
141
fn smoke ( ) {
162
142
#[ derive( Serialize , Deserialize , PartialEq , Debug ) ]
@@ -727,154 +707,6 @@ fn empty_array() {
727
707
run_deserialize_test ( & v, & doc, "empty_array" ) ;
728
708
}
729
709
730
- #[ test]
731
- fn raw_doc_buf ( ) {
732
- #[ derive( Serialize , Deserialize , PartialEq , Debug ) ]
733
- struct Foo {
734
- d : RawDocumentBuf ,
735
- }
736
-
737
- let bytes = bson:: to_vec ( & doc ! {
738
- "d" : {
739
- "a" : 12 ,
740
- "b" : 5.5 ,
741
- "c" : [ 1 , true , "ok" ] ,
742
- "d" : { "a" : "b" } ,
743
- "e" : ObjectId :: new( ) ,
744
- }
745
- } )
746
- . expect ( "raw_doc_buf" ) ;
747
-
748
- run_raw_round_trip_test :: < Foo > ( bytes. as_slice ( ) , "raw_doc_buf" ) ;
749
- }
750
-
751
- #[ test]
752
- fn raw_doc ( ) {
753
- #[ derive( Serialize , Deserialize , PartialEq , Debug ) ]
754
- struct Foo < ' a > {
755
- #[ serde( borrow) ]
756
- d : & ' a RawDocument ,
757
- }
758
-
759
- let bytes = bson:: to_vec ( & doc ! {
760
- "d" : {
761
- "a" : 12 ,
762
- "b" : 5.5 ,
763
- "c" : [ 1 , true , "ok" ] ,
764
- "d" : { "a" : "b" } ,
765
- "e" : ObjectId :: new( ) ,
766
- }
767
- } )
768
- . expect ( "raw doc" ) ;
769
-
770
- run_raw_round_trip_test :: < Foo > ( bytes. as_slice ( ) , "raw_doc" ) ;
771
- }
772
-
773
- #[ test]
774
- fn raw_array ( ) {
775
- #[ derive( Serialize , Deserialize , PartialEq , Debug ) ]
776
- struct Foo < ' a > {
777
- #[ serde( borrow) ]
778
- d : & ' a RawArray ,
779
- }
780
-
781
- let bytes = bson:: to_vec ( & doc ! {
782
- "d" : [ 1 , true , { "ok" : 1 } , [ "sub" , "array" ] , Uuid :: new( ) ]
783
- } )
784
- . expect ( "raw_array" ) ;
785
-
786
- run_raw_round_trip_test :: < Foo > ( bytes. as_slice ( ) , "raw_array" ) ;
787
- }
788
-
789
- #[ test]
790
- fn raw_binary ( ) {
791
- #[ derive( Serialize , Deserialize , PartialEq , Debug ) ]
792
- struct Foo < ' a > {
793
- #[ serde( borrow) ]
794
- generic : RawBinary < ' a > ,
795
-
796
- #[ serde( borrow) ]
797
- old : RawBinary < ' a > ,
798
-
799
- #[ serde( borrow) ]
800
- uuid : RawBinary < ' a > ,
801
-
802
- #[ serde( borrow) ]
803
- other : RawBinary < ' a > ,
804
- }
805
-
806
- let bytes = bson:: to_vec ( & doc ! {
807
- "generic" : Binary {
808
- bytes: vec![ 1 , 2 , 3 , 4 , 5 ] ,
809
- subtype: BinarySubtype :: Generic ,
810
- } ,
811
- "old" : Binary {
812
- bytes: vec![ 1 , 2 , 3 ] ,
813
- subtype: BinarySubtype :: BinaryOld ,
814
- } ,
815
- "uuid" : Uuid :: new( ) ,
816
- "other" : Binary {
817
- bytes: vec![ 1u8 ; 100 ] ,
818
- subtype: BinarySubtype :: UserDefined ( 100 ) ,
819
- }
820
- } )
821
- . expect ( "raw_binary" ) ;
822
-
823
- run_raw_round_trip_test :: < Foo > ( bytes. as_slice ( ) , "raw_binary" ) ;
824
- }
825
-
826
- #[ test]
827
- fn raw_regex ( ) {
828
- #[ derive( Serialize , Deserialize , PartialEq , Debug ) ]
829
- struct Foo < ' a > {
830
- #[ serde( borrow) ]
831
- r : RawRegex < ' a > ,
832
- }
833
-
834
- let bytes = bson:: to_vec ( & doc ! {
835
- "r" : Regex {
836
- pattern: "a[b-c]d" . to_string( ) ,
837
- options: "ab" . to_string( ) ,
838
- } ,
839
- } )
840
- . expect ( "raw_regex" ) ;
841
-
842
- run_raw_round_trip_test :: < Foo > ( bytes. as_slice ( ) , "raw_regex" ) ;
843
- }
844
-
845
- #[ test]
846
- fn raw_code_w_scope ( ) {
847
- #[ derive( Serialize , Deserialize , PartialEq , Debug ) ]
848
- struct Foo < ' a > {
849
- #[ serde( borrow) ]
850
- r : RawJavaScriptCodeWithScope < ' a > ,
851
- }
852
-
853
- let bytes = bson:: to_vec ( & doc ! {
854
- "r" : JavaScriptCodeWithScope {
855
- code: "console.log(x)" . to_string( ) ,
856
- scope: doc! { "x" : 1 } ,
857
- } ,
858
- } )
859
- . expect ( "raw_code_w_scope" ) ;
860
-
861
- run_raw_round_trip_test :: < Foo > ( bytes. as_slice ( ) , "raw_code_w_scope" ) ;
862
- }
863
-
864
- #[ test]
865
- fn raw_db_pointer ( ) {
866
- #[ derive( Serialize , Deserialize , PartialEq , Debug ) ]
867
- struct Foo < ' a > {
868
- #[ serde( borrow) ]
869
- a : RawDbPointer < ' a > ,
870
- }
871
-
872
- // From the "DBpointer" bson corpus test
873
- let bytes = hex:: decode ( "1A0000000C610002000000620056E1FC72E0C917E9C471416100" ) . unwrap ( ) ;
874
-
875
- run_raw_round_trip_test :: < Foo > ( bytes. as_slice ( ) , "raw_db_pointer" ) ;
876
- }
877
-
878
710
#[ derive( Debug , Deserialize , Serialize , PartialEq ) ]
879
711
struct SubDoc {
880
712
a : i32 ,
@@ -1077,64 +909,6 @@ fn all_types_rmp() {
1077
909
assert_eq ! ( back, v) ;
1078
910
}
1079
911
1080
- #[ test]
1081
- fn all_raw_types_rmp ( ) {
1082
- #[ derive( Debug , Serialize , Deserialize , PartialEq ) ]
1083
- struct AllRawTypes < ' a > {
1084
- #[ serde( borrow) ]
1085
- bson : RawBson < ' a > ,
1086
- #[ serde( borrow) ]
1087
- document : & ' a RawDocument ,
1088
- #[ serde( borrow) ]
1089
- array : & ' a RawArray ,
1090
- buf : RawDocumentBuf ,
1091
- #[ serde( borrow) ]
1092
- binary : RawBinary < ' a > ,
1093
- #[ serde( borrow) ]
1094
- code_w_scope : RawJavaScriptCodeWithScope < ' a > ,
1095
- #[ serde( borrow) ]
1096
- regex : RawRegex < ' a > ,
1097
- }
1098
-
1099
- let doc_bytes = bson:: to_vec ( & doc ! {
1100
- "bson" : "some string" ,
1101
- "array" : [ 1 , 2 , 3 ] ,
1102
- "binary" : Binary { bytes: vec![ 1 , 2 , 3 ] , subtype: BinarySubtype :: Generic } ,
1103
- "binary_old" : Binary { bytes: vec![ 1 , 2 , 3 ] , subtype: BinarySubtype :: BinaryOld } ,
1104
- "code_w_scope" : JavaScriptCodeWithScope {
1105
- code: "ok" . to_string( ) ,
1106
- scope: doc! { "x" : 1 } ,
1107
- } ,
1108
- "regex" : Regex {
1109
- pattern: "pattern" . to_string( ) ,
1110
- options: "opt" . to_string( )
1111
- }
1112
- } )
1113
- . unwrap ( ) ;
1114
- let doc_buf = RawDocumentBuf :: new ( doc_bytes) . unwrap ( ) ;
1115
- let document = & doc_buf;
1116
- let array = document. get_array ( "array" ) . unwrap ( ) ;
1117
-
1118
- let v = AllRawTypes {
1119
- bson : document. get ( "bson" ) . unwrap ( ) . unwrap ( ) ,
1120
- array,
1121
- document,
1122
- buf : doc_buf. clone ( ) ,
1123
- binary : document. get_binary ( "binary" ) . unwrap ( ) ,
1124
- code_w_scope : document
1125
- . get ( "code_w_scope" )
1126
- . unwrap ( )
1127
- . unwrap ( )
1128
- . as_javascript_with_scope ( )
1129
- . unwrap ( ) ,
1130
- regex : document. get_regex ( "regex" ) . unwrap ( ) ,
1131
- } ;
1132
- let serialized = rmp_serde:: to_vec_named ( & v) . unwrap ( ) ;
1133
- let back: AllRawTypes = rmp_serde:: from_slice ( & serialized) . unwrap ( ) ;
1134
-
1135
- assert_eq ! ( back, v) ;
1136
- }
1137
-
1138
912
#[ test]
1139
913
fn borrowed ( ) {
1140
914
#[ derive( Debug , Deserialize , PartialEq ) ]
@@ -1280,71 +1054,18 @@ fn serde_with_uuid() {
1280
1054
run_test ( & f, & expected, "serde_with - uuid" ) ;
1281
1055
}
1282
1056
1283
- #[ test]
1284
- fn hint_cleared ( ) {
1285
- #[ derive( Debug , Serialize , Deserialize ) ]
1286
- struct Foo < ' a > {
1287
- #[ serde( borrow) ]
1288
- doc : & ' a RawDocument ,
1289
- #[ serde( borrow) ]
1290
- binary : RawBinary < ' a > ,
1291
- }
1292
-
1293
- let binary_value = Binary {
1294
- bytes : vec ! [ 1 , 2 , 3 , 4 ] ,
1295
- subtype : BinarySubtype :: Generic ,
1296
- } ;
1297
-
1298
- let doc_value = doc ! {
1299
- "binary" : binary_value. clone( )
1300
- } ;
1301
-
1302
- let bytes = bson:: to_vec ( & doc_value) . unwrap ( ) ;
1303
-
1304
- let doc = RawDocument :: new ( & bytes) . unwrap ( ) ;
1305
- let binary = doc. get_binary ( "binary" ) . unwrap ( ) ;
1306
-
1307
- let f = Foo { doc, binary } ;
1308
-
1309
- let serialized_bytes = bson:: to_vec ( & f) . unwrap ( ) ;
1310
- let round_doc: Document = bson:: from_slice ( & serialized_bytes) . unwrap ( ) ;
1311
-
1312
- assert_eq ! ( round_doc, doc! { "doc" : doc_value, "binary" : binary_value } ) ;
1313
- }
1314
-
1315
1057
#[ test]
1316
1058
fn non_human_readable ( ) {
1317
- let bytes = vec ! [ 1 , 2 , 3 , 4 ] ;
1318
- let binary = RawBinary {
1319
- bytes : & bytes,
1320
- subtype : BinarySubtype :: BinaryOld ,
1321
- } ;
1322
-
1323
- let doc_bytes = bson:: to_vec ( & doc ! { "a" : "b" , "array" : [ 1 , 2 , 3 ] } ) . unwrap ( ) ;
1324
- let doc = RawDocument :: new ( doc_bytes. as_slice ( ) ) . unwrap ( ) ;
1325
- let arr = doc. get_array ( "array" ) . unwrap ( ) ;
1326
1059
let oid = ObjectId :: new ( ) ;
1327
1060
let uuid = Uuid :: new ( ) ;
1328
1061
1329
1062
#[ derive( Debug , Deserialize , Serialize ) ]
1330
- struct Foo < ' a > {
1331
- #[ serde( borrow) ]
1332
- binary : RawBinary < ' a > ,
1333
- #[ serde( borrow) ]
1334
- doc : & ' a RawDocument ,
1335
- #[ serde( borrow) ]
1336
- arr : & ' a RawArray ,
1063
+ struct Foo {
1337
1064
oid : ObjectId ,
1338
1065
uuid : Uuid ,
1339
1066
}
1340
1067
1341
- let val = Foo {
1342
- binary,
1343
- doc,
1344
- arr,
1345
- oid,
1346
- uuid,
1347
- } ;
1068
+ let val = Foo { oid, uuid } ;
1348
1069
1349
1070
let human_readable = bson:: to_bson ( & val) . unwrap ( ) ;
1350
1071
let non_human_readable = bson:: to_bson_with_options (
@@ -1354,12 +1075,6 @@ fn non_human_readable() {
1354
1075
. unwrap ( ) ;
1355
1076
1356
1077
let expected = bson ! ( {
1357
- "binary" : Binary { bytes: bytes. clone( ) , subtype: BinarySubtype :: BinaryOld } ,
1358
- "doc" : {
1359
- "a" : "b" ,
1360
- "array" : [ 1 , 2 , 3 ] ,
1361
- } ,
1362
- "arr" : [ 1 , 2 , 3 ] ,
1363
1078
"oid" : oid,
1364
1079
"uuid" : uuid
1365
1080
} ) ;
0 commit comments