@@ -18,6 +18,7 @@ use std::{
1818} ;
1919
2020use bson:: {
21+ cstr,
2122 doc,
2223 oid:: ObjectId ,
2324 spec:: BinarySubtype ,
@@ -835,8 +836,8 @@ fn raw_regex() {
835836
836837 let bytes = bson:: serialize_to_vec ( & doc ! {
837838 "r" : Regex {
838- pattern: "a[b-c]d" . to_string ( ) ,
839- options: "ab" . to_string ( ) ,
839+ pattern: cstr! ( "a[b-c]d" ) . into ( ) ,
840+ options: cstr! ( "ab" ) . into ( ) ,
840841 } ,
841842 } )
842843 . expect ( "raw_regex" ) ;
@@ -927,8 +928,8 @@ impl AllTypes {
927928 } ;
928929 let date = DateTime :: now ( ) ;
929930 let regex = Regex {
930- pattern : "hello" . to_string ( ) ,
931- options : "x" . to_string ( ) ,
931+ pattern : cstr ! ( "hello" ) . into ( ) ,
932+ options : cstr ! ( "x" ) . into ( ) ,
932933 } ;
933934 let timestamp = Timestamp {
934935 time : 123 ,
@@ -1058,8 +1059,8 @@ fn all_raw_types_rmp() {
10581059 scope: doc! { "x" : 1 } ,
10591060 } ,
10601061 "regex" : Regex {
1061- pattern: "pattern" . to_string ( ) ,
1062- options: "opt" . to_string ( )
1062+ pattern: cstr! ( "pattern" ) . into ( ) ,
1063+ options: cstr! ( "opt" ) . into ( )
10631064 }
10641065 } )
10651066 . unwrap ( ) ;
@@ -1254,24 +1255,22 @@ fn owned_raw_types() {
12541255
12551256 let f = Foo {
12561257 subdoc : RawDocumentBuf :: from_iter ( [
1257- ( "a key" , RawBson :: String ( "a value" . to_string ( ) ) ) ,
1258- ( "an objectid" , RawBson :: ObjectId ( oid) ) ,
1259- ( "a date" , RawBson :: DateTime ( dt) ) ,
1258+ ( cstr ! ( "a key" ) , RawBson :: String ( "a value" . to_string ( ) ) ) ,
1259+ ( cstr ! ( "an objectid" ) , RawBson :: ObjectId ( oid) ) ,
1260+ ( cstr ! ( "a date" ) , RawBson :: DateTime ( dt) ) ,
12601261 (
1261- "code_w_scope" ,
1262+ cstr ! ( "code_w_scope" ) ,
12621263 RawBson :: JavaScriptCodeWithScope ( raw_code_w_scope. clone ( ) ) ,
12631264 ) ,
1264- ( "decimal128" , RawBson :: Decimal128 ( d128) ) ,
1265- ] )
1266- . unwrap ( ) ,
1265+ ( cstr ! ( "decimal128" ) , RawBson :: Decimal128 ( d128) ) ,
1266+ ] ) ,
12671267 array : RawArrayBuf :: from_iter ( [
12681268 RawBson :: String ( "a string" . to_string ( ) ) ,
12691269 RawBson :: ObjectId ( oid) ,
12701270 RawBson :: DateTime ( dt) ,
12711271 RawBson :: JavaScriptCodeWithScope ( raw_code_w_scope) ,
12721272 RawBson :: Decimal128 ( d128) ,
1273- ] )
1274- . unwrap ( ) ,
1273+ ] ) ,
12751274 } ;
12761275
12771276 let expected = doc ! {
0 commit comments