File tree Expand file tree Collapse file tree 3 files changed +11
-12
lines changed
Expand file tree Collapse file tree 3 files changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ impl<'de> Deserializer<'de> {
7171 V : serde:: de:: Visitor < ' de > ,
7272 {
7373 if self . options . utf8_lossy {
74- if let Some ( lossy) = self . element . value_utf8_lossy ( ) ? {
74+ if let Some ( lossy) = self . element . value_utf8_lossy_inner ( ) ? {
7575 return match lossy {
7676 Utf8LossyBson :: String ( s) => visitor. visit_string ( s) ,
7777 Utf8LossyBson :: RegularExpression ( re) => {
@@ -178,7 +178,7 @@ impl<'de> Deserializer<'de> {
178178
179179 fn get_string ( & self ) -> Result < Cow < ' de , str > > {
180180 if self . options . utf8_lossy {
181- let value = self . element . value_utf8_lossy ( ) ?;
181+ let value = self . element . value_utf8_lossy_inner ( ) ?;
182182 let s = match value {
183183 Some ( Utf8LossyBson :: String ( s) ) => s,
184184 _ => {
Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ use crate::{
1010 error:: { Error , Result } ,
1111 raw:: { serde:: OwnedOrBorrowedRawDocument , RAW_DOCUMENT_NEWTYPE } ,
1212 DateTime ,
13- RawBson ,
1413 Timestamp ,
1514} ;
1615
@@ -520,14 +519,7 @@ impl RawDocument {
520519 pub fn to_document_utf8_lossy ( & self ) -> Result < Document > {
521520 self . iter_elements ( )
522521 . map ( |res| {
523- res. and_then ( |e| {
524- let key = e. key ( ) . to_owned ( ) ;
525- let raw_value: RawBson = match e. value_utf8_lossy ( ) ? {
526- Some ( l) => l. into ( ) ,
527- None => e. value ( ) ?. to_raw_bson ( ) ,
528- } ;
529- Ok ( ( key, raw_value. try_into ( ) ?) )
530- } )
522+ res. and_then ( |e| Ok ( ( e. key ( ) . to_owned ( ) , e. value_utf8_lossy ( ) ?. try_into ( ) ?) ) )
531523 } )
532524 . collect ( )
533525 }
Original file line number Diff line number Diff line change @@ -265,7 +265,14 @@ impl<'a> RawElement<'a> {
265265 } )
266266 }
267267
268- pub ( crate ) fn value_utf8_lossy ( & self ) -> Result < Option < Utf8LossyBson < ' a > > > {
268+ pub fn value_utf8_lossy ( & self ) -> Result < RawBson > {
269+ match self . value_utf8_lossy_inner ( ) ? {
270+ Some ( v) => Ok ( v. into ( ) ) ,
271+ None => Ok ( self . value ( ) ?. to_raw_bson ( ) ) ,
272+ }
273+ }
274+
275+ pub ( crate ) fn value_utf8_lossy_inner ( & self ) -> Result < Option < Utf8LossyBson < ' a > > > {
269276 Ok ( Some ( match self . kind {
270277 ElementType :: String => Utf8LossyBson :: String ( self . read_utf8_lossy ( ) ) ,
271278 ElementType :: JavaScriptCode => Utf8LossyBson :: JavaScriptCode ( self . read_utf8_lossy ( ) ) ,
You can’t perform that action at this time.
0 commit comments