From 01183544785e2863b2edab569ef7f942db42a43f Mon Sep 17 00:00:00 2001 From: Titouan Rigoudy Date: Sun, 23 Sep 2018 16:52:02 +0000 Subject: [PATCH] Implement Encode using ProtoEncode. First step towards hiding ProtoEncode as an implementation detail and only exposing Encode externally. --- src/proto/base_codec.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/proto/base_codec.rs b/src/proto/base_codec.rs index b228e8b..6247707 100644 --- a/src/proto/base_codec.rs +++ b/src/proto/base_codec.rs @@ -162,6 +162,8 @@ where /// This trait is implemented by types that can be encoded into messages with /// a `ProtoEncoder`. /// Only here to enable `ProtoEncoder::encode_vec`. +/// Attempting to implement Encode for Vec otherwise fails because none of +/// the types involved are defined in this crate. pub trait ProtoEncode { /// Attempts to encode `self` with the given encoder. fn encode(&self, encoder: &mut ProtoEncoder) -> io::Result<()>; @@ -308,6 +310,12 @@ impl ProtoEncode for Vec { } } +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 * *=======*/