@@ -3,7 +3,7 @@ use std::convert::{TryFrom, TryInto};
33use super :: { bson:: RawBson , Error , RawArray , RawDocument , Result } ;
44use crate :: {
55 oid:: { self , ObjectId } ,
6- raw:: { write_cstring , write_string , RawJavaScriptCodeWithScope } ,
6+ raw:: { write_string , CStr , RawJavaScriptCodeWithScope } ,
77 spec:: { BinarySubtype , ElementType } ,
88 Binary ,
99 Bson ,
@@ -255,9 +255,10 @@ impl<'a> RawBsonRef<'a> {
255255 RawBsonRef :: Document ( d) => RawBson :: Document ( d. to_owned ( ) ) ,
256256 RawBsonRef :: Boolean ( b) => RawBson :: Boolean ( b) ,
257257 RawBsonRef :: Null => RawBson :: Null ,
258- RawBsonRef :: RegularExpression ( re) => {
259- RawBson :: RegularExpression ( Regex :: new ( re. pattern , re. options ) )
260- }
258+ RawBsonRef :: RegularExpression ( re) => RawBson :: RegularExpression ( Regex {
259+ pattern : re. pattern . into ( ) ,
260+ options : re. options . into ( ) ,
261+ } ) ,
261262 RawBsonRef :: JavaScriptCode ( c) => RawBson :: JavaScriptCode ( c. to_owned ( ) ) ,
262263 RawBsonRef :: JavaScriptCodeWithScope ( c_w_s) => {
263264 RawBson :: JavaScriptCodeWithScope ( RawJavaScriptCodeWithScope {
@@ -306,8 +307,8 @@ impl<'a> RawBsonRef<'a> {
306307 Self :: Document ( raw_document) => dest. extend ( raw_document. as_bytes ( ) ) ,
307308 Self :: Boolean ( b) => dest. push ( b as u8 ) ,
308309 Self :: RegularExpression ( re) => {
309- write_cstring ( dest , re. pattern ) ? ;
310- write_cstring ( dest , re. options ) ? ;
310+ re. pattern . append_to ( dest ) ;
311+ re. options . append_to ( dest ) ;
311312 }
312313 Self :: JavaScriptCode ( js) => write_string ( dest, js) ,
313314 Self :: JavaScriptCodeWithScope ( code_w_scope) => {
@@ -592,7 +593,7 @@ impl<'a> From<&'a Binary> for RawBsonRef<'a> {
592593#[ derive( Clone , Copy , Debug , PartialEq ) ]
593594pub struct RawRegexRef < ' a > {
594595 /// The regex pattern to match.
595- pub pattern : & ' a str ,
596+ pub pattern : & ' a CStr ,
596597
597598 /// The options for the regex.
598599 ///
@@ -601,7 +602,7 @@ pub struct RawRegexRef<'a> {
601602 /// multiline matching, 'x' for verbose mode, 'l' to make \w, \W, etc. locale dependent,
602603 /// 's' for dotall mode ('.' matches everything), and 'u' to make \w, \W, etc. match
603604 /// unicode.
604- pub options : & ' a str ,
605+ pub options : & ' a CStr ,
605606}
606607
607608#[ cfg( feature = "serde" ) ]
0 commit comments