From dbedc6083e9f3c3c3066753c068981d59aa8dc9f Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Thu, 9 Dec 2021 00:03:56 +0000 Subject: [PATCH] :recycle: refactor: fix some unused code warnings --- src/message.rs | 16 +++++++--------- src/tlv.rs | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/message.rs b/src/message.rs index 3acdeb2..3baf394 100644 --- a/src/message.rs +++ b/src/message.rs @@ -19,10 +19,10 @@ pub enum Message { // 1 Request1 { idem_id: [u8; 8], - mac: Option <[u8; 6]> + mac: Option }, // 2 - Response1 (Option <[u8; 6]>), + Response1 (Option ), // 3 Response2 (Response2), } @@ -66,7 +66,7 @@ impl Write for DummyWriter { } impl Message { - pub fn write (&self, w: &mut Cursor ) -> Result <(), std::io::Error> + pub fn write (&self, w: &mut Cursor ) -> Result <(), MessageError> where Cursor : Write { match self { @@ -102,13 +102,11 @@ impl Message { } fn write_response_2 (w: &mut W, params: &Response2) - -> Result <(), std::io::Error> + -> Result <(), MessageError> { w.write_all (¶ms.idem_id)?; let nickname = params.nickname.as_bytes (); - let nickname_len = u32::try_from (nickname.len ()).unwrap (); - w.write_all (&nickname_len.to_le_bytes ())?; - w.write_all (&nickname)?; + tlv::Writer::<_>::lv_bytes (w, nickname)?; Ok (()) } @@ -124,14 +122,14 @@ impl Message { Ok (()) } - pub fn to_vec (&self) -> Result , tlv::TlvError> { + pub fn to_vec (&self) -> Result , MessageError> { let mut cursor = Cursor::new (Vec::with_capacity (PACKET_SIZE)); cursor.write_all (&MAGIC_NUMBER)?; self.write (&mut cursor)?; Ok (cursor.into_inner ()) } - pub fn many_to_vec (msgs: &[Self]) -> Result , tlv::TlvError> { + pub fn many_to_vec (msgs: &[Self]) -> Result , MessageError> { let mut cursor = Cursor::new (Vec::with_capacity (PACKET_SIZE)); cursor.write_all (&MAGIC_NUMBER)?; for msg in msgs { diff --git a/src/tlv.rs b/src/tlv.rs index a083dd9..fbb4121 100644 --- a/src/tlv.rs +++ b/src/tlv.rs @@ -61,7 +61,7 @@ impl Reader { Ok (u32::from_le_bytes (buf)) } - pub fn lv_bytes (r: &mut R, buf: &mut [u8]) -> Result { + fn lv_bytes (r: &mut R, buf: &mut [u8]) -> Result { let l = Self::length (r)?; if usize::try_from (l)? > buf.len () { return Err (TlvError::CallerBufferTooSmall);