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 @@ -9,7 +9,6 @@ use crate::{
99 de:: MIN_BSON_DOCUMENT_SIZE ,
1010 raw:: { error:: ErrorKind , serde:: OwnedOrBorrowedRawDocument , RAW_DOCUMENT_NEWTYPE } ,
1111 DateTime ,
12- RawBson ,
1312 Timestamp ,
1413} ;
1514
@@ -543,14 +542,7 @@ impl RawDocument {
543542 pub fn to_document_utf8_lossy ( & self ) -> Result < Document > {
544543 self . iter_elements ( )
545544 . map ( |res| {
546- res. and_then ( |e| {
547- let key = e. key ( ) . to_owned ( ) ;
548- let raw_value: RawBson = match e. value_utf8_lossy ( ) ? {
549- Some ( l) => l. into ( ) ,
550- None => e. value ( ) ?. to_raw_bson ( ) ,
551- } ;
552- Ok ( ( key, raw_value. try_into ( ) ?) )
553- } )
545+ res. and_then ( |e| Ok ( ( e. key ( ) . to_owned ( ) , e. value_utf8_lossy ( ) ?. try_into ( ) ?) ) )
554546 } )
555547 . collect ( )
556548 }
Original file line number Diff line number Diff line change @@ -266,7 +266,14 @@ impl<'a> RawElement<'a> {
266266 } )
267267 }
268268
269- pub ( crate ) fn value_utf8_lossy ( & self ) -> Result < Option < Utf8LossyBson < ' a > > > {
269+ pub fn value_utf8_lossy ( & self ) -> Result < RawBson > {
270+ match self . value_utf8_lossy_inner ( ) ? {
271+ Some ( v) => Ok ( v. into ( ) ) ,
272+ None => Ok ( self . value ( ) ?. to_raw_bson ( ) ) ,
273+ }
274+ }
275+
276+ pub ( crate ) fn value_utf8_lossy_inner ( & self ) -> Result < Option < Utf8LossyBson < ' a > > > {
270277 Ok ( Some ( match self . kind {
271278 ElementType :: String => Utf8LossyBson :: String ( self . read_utf8_lossy ( ) ) ,
272279 ElementType :: JavaScriptCode => Utf8LossyBson :: JavaScriptCode ( self . read_utf8_lossy ( ) ) ,
You can’t perform that action at this time.
0 commit comments