From: Sachandhan Ganesh Date: Sat, 13 Feb 2021 07:20:59 +0000 (-0800) Subject: serializing a datagram should consume itself X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=37ff5647aa52ff24822fdacfd953b0dbe70a5a42;p=connect-rs.git serializing a datagram should consume itself --- diff --git a/src/protocol.rs b/src/protocol.rs index 1ae2779..73da4bc 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -21,6 +21,7 @@ impl std::fmt::Display for DatagramEmptyError { /// A simple packet format containing a version, recipient tag, and message body. /// +#[derive(Clone)] pub struct ConnectDatagram { version: u8, recipient: u16, @@ -84,7 +85,7 @@ impl ConnectDatagram { 3 + data_len } - /// Constructs a serialized representation of the datagram. + /// Constructs a serialized representation of the datagram contents. /// pub(crate) fn bytes(&self) -> Vec { let mut bytes = Vec::with_capacity(self.size()); @@ -101,7 +102,7 @@ impl ConnectDatagram { /// Serializes the datagram. /// - pub fn encode(&self) -> Vec { + pub fn encode(self) -> Vec { let size: u32 = (self.size()) as u32; let mut bytes = Vec::from(size.to_be_bytes());