@@ -29,20 +29,18 @@ pub(crate) fn cstr_to_str(cs: &CStr) -> &str {
29
29
}
30
30
}
31
31
32
+ #[ cfg( feature = "bson-3" ) ]
32
33
pub ( crate ) trait RawDocumentBufExt : Sized {
33
- fn append_ref_compat < ' a > (
34
+ fn append_ref < ' a > (
34
35
& mut self ,
35
36
key : impl AsRef < CStr > ,
36
37
value : impl Into < crate :: bson:: raw:: RawBsonRef < ' a > > + ' a ,
37
38
) ;
38
-
39
- #[ cfg( not( feature = "bson-3" ) ) ]
40
- fn decode_from_bytes ( data : Vec < u8 > ) -> RawResult < Self > ;
41
39
}
42
40
43
41
#[ cfg( feature = "bson-3" ) ]
44
42
impl RawDocumentBufExt for crate :: bson:: RawDocumentBuf {
45
- fn append_ref_compat < ' a > (
43
+ fn append_ref < ' a > (
46
44
& mut self ,
47
45
key : impl AsRef < CStr > ,
48
46
value : impl Into < crate :: bson:: raw:: RawBsonRef < ' a > > + ' a ,
@@ -51,45 +49,15 @@ impl RawDocumentBufExt for crate::bson::RawDocumentBuf {
51
49
}
52
50
}
53
51
54
- #[ cfg( not( feature = "bson-3" ) ) ]
55
- impl RawDocumentBufExt for crate :: bson:: RawDocumentBuf {
56
- fn append_ref_compat < ' a > (
57
- & mut self ,
58
- key : impl AsRef < CStr > ,
59
- value : impl Into < crate :: bson:: raw:: RawBsonRef < ' a > > ,
60
- ) {
61
- self . append_ref ( key, value)
62
- }
63
-
64
- fn decode_from_bytes ( data : Vec < u8 > ) -> RawResult < Self > {
65
- Self :: from_bytes ( data)
66
- }
67
- }
68
-
69
- #[ cfg( not( feature = "bson-3" ) ) ]
70
- pub ( crate ) trait RawDocumentExt {
71
- fn decode_from_bytes < D : AsRef < [ u8 ] > + ?Sized > ( data : & D ) -> RawResult < & Self > ;
72
- }
73
-
74
- #[ cfg( not( feature = "bson-3" ) ) ]
75
- impl RawDocumentExt for crate :: bson:: RawDocument {
76
- fn decode_from_bytes < D : AsRef < [ u8 ] > + ?Sized > ( data : & D ) -> RawResult < & Self > {
77
- Self :: from_bytes ( data)
78
- }
79
- }
80
-
81
- #[ cfg( not( feature = "bson-3" ) ) ]
82
- #[ allow( dead_code) ]
83
- pub ( crate ) trait DocumentExt {
84
- fn encode_to_vec ( & self ) -> crate :: bson:: ser:: Result < Vec < u8 > > ;
52
+ #[ cfg( feature = "bson-3" ) ]
53
+ pub ( crate ) trait RawBsonRefExt {
54
+ fn to_raw_bson ( & self ) -> crate :: bson:: RawBson ;
85
55
}
86
56
87
- #[ cfg( not( feature = "bson-3" ) ) ]
88
- impl DocumentExt for crate :: bson:: Document {
89
- fn encode_to_vec ( & self ) -> crate :: bson:: ser:: Result < Vec < u8 > > {
90
- let mut out = vec ! [ ] ;
91
- self . to_writer ( & mut out) ?;
92
- Ok ( out)
57
+ #[ cfg( feature = "bson-3" ) ]
58
+ impl RawBsonRefExt for crate :: bson:: RawBsonRef < ' _ > {
59
+ fn to_raw_bson ( & self ) -> crate :: bson:: RawBson {
60
+ ( * self ) . into ( )
93
61
}
94
62
}
95
63
@@ -113,6 +81,7 @@ use_either! {
113
81
RawError => error:: Error | raw:: Error ;
114
82
DeError => error:: Error | de:: Error ;
115
83
SerError => error:: Error | ser:: Error ;
84
+ Utf8Lossy => Utf8Lossy | serde_helpers:: Utf8LossyDeserialization ;
116
85
serialize_to_raw_document_buf => serialize_to_raw_document_buf | to_raw_document_buf;
117
86
serialize_to_document => serialize_to_document | to_document;
118
87
serialize_to_bson => serialize_to_bson | to_bson;
0 commit comments