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:: { error:: ErrorKind , serde:: OwnedOrBorrowedRawDocument , RAW_DOCUMENT_NEWTYPE } ,
1212 DateTime ,
13- RawBson ,
1413 Timestamp ,
1514} ;
1615
@@ -535,14 +534,7 @@ impl RawDocument {
535534 pub fn to_document_utf8_lossy ( & self ) -> Result < Document > {
536535 self . iter_elements ( )
537536 . map ( |res| {
538- res. and_then ( |e| {
539- let key = e. key ( ) . to_owned ( ) ;
540- let raw_value: RawBson = match e. value_utf8_lossy ( ) ? {
541- Some ( l) => l. into ( ) ,
542- None => e. value ( ) ?. to_raw_bson ( ) ,
543- } ;
544- Ok ( ( key, raw_value. try_into ( ) ?) )
545- } )
537+ res. and_then ( |e| Ok ( ( e. key ( ) . to_owned ( ) , e. value_utf8_lossy ( ) ?. try_into ( ) ?) ) )
546538 } )
547539 . collect ( )
548540 }
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