Browse Source

Implement Encode using ProtoEncode.

First step towards hiding ProtoEncode as an implementation detail and
only exposing Encode externally.
wip
Titouan Rigoudy 7 years ago
parent
commit
0118354478
1 changed files with 8 additions and 0 deletions
  1. +8
    -0
      src/proto/base_codec.rs

+ 8
- 0
src/proto/base_codec.rs View File

@ -162,6 +162,8 @@ where
/// This trait is implemented by types that can be encoded into messages with /// This trait is implemented by types that can be encoded into messages with
/// a `ProtoEncoder`. /// a `ProtoEncoder`.
/// Only here to enable `ProtoEncoder::encode_vec`. /// Only here to enable `ProtoEncoder::encode_vec`.
/// Attempting to implement Encode for Vec<T> otherwise fails because none of
/// the types involved are defined in this crate.
pub trait ProtoEncode { pub trait ProtoEncode {
/// Attempts to encode `self` with the given encoder. /// Attempts to encode `self` with the given encoder.
fn encode(&self, encoder: &mut ProtoEncoder) -> io::Result<()>; fn encode(&self, encoder: &mut ProtoEncoder) -> io::Result<()>;
@ -308,6 +310,12 @@ impl<T: ProtoEncode> ProtoEncode for Vec<T> {
} }
} }
impl<'a, T: ProtoEncode> Encode<&'a T> for BytesMut {
fn encode(&mut self, value: &'a T) -> io::Result<()> {
value.encode(&mut ProtoEncoder::new(self))
}
}
/*=======* /*=======*
* TESTS * * TESTS *
*=======*/ *=======*/


Loading…
Cancel
Save