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> {
71
71
V : serde:: de:: Visitor < ' de > ,
72
72
{
73
73
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 ( ) ? {
75
75
return match lossy {
76
76
Utf8LossyBson :: String ( s) => visitor. visit_string ( s) ,
77
77
Utf8LossyBson :: RegularExpression ( re) => {
@@ -178,7 +178,7 @@ impl<'de> Deserializer<'de> {
178
178
179
179
fn get_string ( & self ) -> Result < Cow < ' de , str > > {
180
180
if self . options . utf8_lossy {
181
- let value = self . element . value_utf8_lossy ( ) ?;
181
+ let value = self . element . value_utf8_lossy_inner ( ) ?;
182
182
let s = match value {
183
183
Some ( Utf8LossyBson :: String ( s) ) => s,
184
184
_ => {
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ use crate::{
9
9
de:: MIN_BSON_DOCUMENT_SIZE ,
10
10
raw:: { error:: ErrorKind , serde:: OwnedOrBorrowedRawDocument , RAW_DOCUMENT_NEWTYPE } ,
11
11
DateTime ,
12
- RawBson ,
13
12
Timestamp ,
14
13
} ;
15
14
@@ -543,14 +542,7 @@ impl RawDocument {
543
542
pub fn to_document_utf8_lossy ( & self ) -> Result < Document > {
544
543
self . iter_elements ( )
545
544
. 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 ( ) ?) ) )
554
546
} )
555
547
. collect ( )
556
548
}
Original file line number Diff line number Diff line change @@ -266,7 +266,14 @@ impl<'a> RawElement<'a> {
266
266
} )
267
267
}
268
268
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 > > > {
270
277
Ok ( Some ( match self . kind {
271
278
ElementType :: String => Utf8LossyBson :: String ( self . read_utf8_lossy ( ) ) ,
272
279
ElementType :: JavaScriptCode => Utf8LossyBson :: JavaScriptCode ( self . read_utf8_lossy ( ) ) ,
You can’t perform that action at this time.
0 commit comments