File tree Expand file tree Collapse file tree 3 files changed +13
-24
lines changed Expand file tree Collapse file tree 3 files changed +13
-24
lines changed Original file line number Diff line number Diff line change @@ -498,18 +498,6 @@ impl RawDocument {
498
498
let s = try_to_str ( bytes) ?;
499
499
s. try_into ( )
500
500
}
501
-
502
- /// Copy this into a [`Document`], returning an error if invalid BSON is encountered. Any
503
- /// invalid UTF-8 sequences will be replaced with the Unicode replacement character.
504
- pub fn to_document_utf8_lossy ( & self ) -> RawResult < Document > {
505
- let mut out = Document :: new ( ) ;
506
- for elem in self . iter_elements ( ) {
507
- let elem = elem?;
508
- let value = deep_utf8_lossy ( elem. value_utf8_lossy ( ) ?) ?;
509
- out. insert ( elem. key ( ) . as_str ( ) , value) ;
510
- }
511
- Ok ( out)
512
- }
513
501
}
514
502
515
503
#[ cfg( feature = "serde" ) ]
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ use crate::{
21
21
RawDocumentBuf ,
22
22
Regex ,
23
23
Timestamp ,
24
+ Utf8Lossy ,
24
25
} ;
25
26
use serde_json:: json;
26
27
@@ -74,11 +75,11 @@ fn test_encode_decode_utf8_string_invalid() {
74
75
doc. to_writer ( & mut buf) . unwrap ( ) ;
75
76
76
77
let expected = doc ! { "key" : "��" , "subdoc" : { "subkey" : "��" } } ;
77
- let decoded = RawDocumentBuf :: from_reader ( & mut Cursor :: new ( buf) )
78
+ let decoded: Utf8Lossy < Document > = RawDocumentBuf :: from_reader ( & mut Cursor :: new ( buf) )
78
79
. unwrap ( )
79
- . to_document_utf8_lossy ( )
80
+ . try_into ( )
80
81
. unwrap ( ) ;
81
- assert_eq ! ( decoded, expected) ;
82
+ assert_eq ! ( decoded. 0 , expected) ;
82
83
}
83
84
84
85
#[ test]
Original file line number Diff line number Diff line change @@ -562,15 +562,15 @@ fn run_test(test: TestFile) {
562
562
. expect_err ( description. as_str ( ) ) ;
563
563
564
564
if decode_error. description . contains ( "invalid UTF-8" ) {
565
- RawDocumentBuf :: from_reader ( bson . as_slice ( ) )
566
- . expect ( & description)
567
- . to_document_utf8_lossy ( )
568
- . unwrap_or_else ( |err| {
569
- panic ! (
570
- "{}: utf8_lossy should not fail (failed with {:?})" ,
571
- description, err
572
- )
573
- } ) ;
565
+ Utf8Lossy :: < Document > :: try_from (
566
+ RawDocumentBuf :: from_reader ( bson . as_slice ( ) ) . expect ( & description) ,
567
+ )
568
+ . unwrap_or_else ( |err| {
569
+ panic ! (
570
+ "{}: utf8_lossy should not fail (failed with {:?})" ,
571
+ description, err
572
+ )
573
+ } ) ;
574
574
crate :: deserialize_from_slice :: < Utf8Lossy < Document > > ( bson. as_slice ( ) )
575
575
. expect ( & description) ;
576
576
}
You can’t perform that action at this time.
0 commit comments