File tree Expand file tree Collapse file tree 4 files changed +40
-6
lines changed Expand file tree Collapse file tree 4 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -47,8 +47,7 @@ pub trait BytesEncode<'a> {
4747 /// Encode the given item as bytes.
4848 fn bytes_encode ( item : & ' a Self :: EItem ) -> Result < Self :: ReturnBytes , Self :: Error > ;
4949
50- /// Encode the given item as bytes and write it into the writer. Returns the amount of bytes
51- /// that were written.
50+ /// Encode the given item as bytes and write it into the writer.
5251 ///
5352 /// When implementing this, also take a look at [`zero_copy`][BytesEncode::zero_copy]'s
5453 /// documentation.
@@ -57,13 +56,12 @@ pub trait BytesEncode<'a> {
5756 fn bytes_encode_into_writer < W : io:: Write > (
5857 item : & ' a Self :: EItem ,
5958 writer : & mut W ,
60- ) -> Result < usize , BoxedError > {
59+ ) -> Result < ( ) , BoxedError > {
6160 let bytes = Self :: bytes_encode ( item) ?;
62- let bytes = bytes. as_ref ( ) ;
6361
64- writer. write_all ( bytes) ?;
62+ writer. write_all ( bytes. as_ref ( ) ) ?;
6563
66- Ok ( bytes . len ( ) )
64+ Ok ( ( ) )
6765 }
6866}
6967
Original file line number Diff line number Diff line change 1616
1717 type Error = bincode:: Error ;
1818
19+ fn zero_copy ( _item : & Self :: EItem ) -> bool {
20+ false
21+ }
22+
1923 fn bytes_encode ( item : & Self :: EItem ) -> Result < Self :: ReturnBytes , Self :: Error > {
2024 bincode:: serialize ( item)
2125 }
26+
27+ fn bytes_encode_into_writer < W : std:: io:: Write > (
28+ item : & ' a Self :: EItem ,
29+ writer : & mut W ,
30+ ) -> Result < ( ) , BoxedError > {
31+ bincode:: serialize_into ( writer, item) ?;
32+ Ok ( ( ) )
33+ }
2234}
2335
2436impl < ' a , T : ' a > BytesDecode < ' a > for SerdeBincode < T >
Original file line number Diff line number Diff line change 1616
1717 type Error = serde_json:: Error ;
1818
19+ fn zero_copy ( _item : & Self :: EItem ) -> bool {
20+ false
21+ }
22+
1923 fn bytes_encode ( item : & Self :: EItem ) -> Result < Self :: ReturnBytes , Self :: Error > {
2024 serde_json:: to_vec ( item)
2125 }
26+
27+ fn bytes_encode_into_writer < W : std:: io:: Write > (
28+ item : & ' a Self :: EItem ,
29+ writer : & mut W ,
30+ ) -> Result < ( ) , BoxedError > {
31+ serde_json:: to_writer ( writer, item) ?;
32+ Ok ( ( ) )
33+ }
2234}
2335
2436impl < ' a , T : ' a > BytesDecode < ' a > for SerdeJson < T >
Original file line number Diff line number Diff line change 1616
1717 type Error = rmp_serde:: encode:: Error ;
1818
19+ fn zero_copy ( _item : & Self :: EItem ) -> bool {
20+ false
21+ }
22+
1923 fn bytes_encode ( item : & Self :: EItem ) -> Result < Self :: ReturnBytes , Self :: Error > {
2024 rmp_serde:: to_vec ( item)
2125 }
26+
27+ fn bytes_encode_into_writer < W : std:: io:: Write > (
28+ item : & ' a Self :: EItem ,
29+ writer : & mut W ,
30+ ) -> Result < ( ) , BoxedError > {
31+ rmp_serde:: encode:: write ( writer, item) ?;
32+ Ok ( ( ) )
33+ }
2234}
2335
2436impl < ' a , T : ' a > BytesDecode < ' a > for SerdeRmp < T >
You can’t perform that action at this time.
0 commit comments