@@ -29,20 +29,18 @@ pub(crate) fn cstr_to_str(cs: &CStr) -> &str {
2929 }
3030}
3131
32+ #[ cfg( feature = "bson-3" ) ]
3233pub ( crate ) trait RawDocumentBufExt : Sized {
33- fn append_ref_compat < ' a > (
34+ fn append_ref < ' a > (
3435 & mut self ,
3536 key : impl AsRef < CStr > ,
3637 value : impl Into < crate :: bson:: raw:: RawBsonRef < ' a > > + ' a ,
3738 ) ;
38-
39- #[ cfg( not( feature = "bson-3" ) ) ]
40- fn decode_from_bytes ( data : Vec < u8 > ) -> RawResult < Self > ;
4139}
4240
4341#[ cfg( feature = "bson-3" ) ]
4442impl RawDocumentBufExt for crate :: bson:: RawDocumentBuf {
45- fn append_ref_compat < ' a > (
43+ fn append_ref < ' a > (
4644 & mut self ,
4745 key : impl AsRef < CStr > ,
4846 value : impl Into < crate :: bson:: raw:: RawBsonRef < ' a > > + ' a ,
@@ -51,45 +49,15 @@ impl RawDocumentBufExt for crate::bson::RawDocumentBuf {
5149 }
5250}
5351
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 ;
8555}
8656
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 ( )
9361 }
9462}
9563
@@ -113,6 +81,7 @@ use_either! {
11381 RawError => error:: Error | raw:: Error ;
11482 DeError => error:: Error | de:: Error ;
11583 SerError => error:: Error | ser:: Error ;
84+ Utf8Lossy => Utf8Lossy | serde_helpers:: Utf8LossyDeserialization ;
11685 serialize_to_raw_document_buf => serialize_to_raw_document_buf | to_raw_document_buf;
11786 serialize_to_document => serialize_to_document | to_document;
11887 serialize_to_bson => serialize_to_bson | to_bson;
0 commit comments