From b0de3a4fb5386e5c9a719b2fc9b891708c2c421d Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Wed, 15 May 2024 23:08:54 +0200 Subject: [PATCH] clippy fix --- servicepoint2/src/bit_vec.rs | 6 +++--- servicepoint2/src/command.rs | 4 ++-- servicepoint2/src/compression.rs | 4 ++-- servicepoint2/src/connection.rs | 3 +-- servicepoint2/src/packet.rs | 6 +++--- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/servicepoint2/src/bit_vec.rs b/servicepoint2/src/bit_vec.rs index 98d6421..90f0f5b 100644 --- a/servicepoint2/src/bit_vec.rs +++ b/servicepoint2/src/bit_vec.rs @@ -39,7 +39,7 @@ impl BitVec { byte & (u8::MAX ^ bit_mask) }; - return old_value; + old_value } /// Gets the value of a bit. @@ -51,7 +51,7 @@ impl BitVec { /// returns: value of the bit pub fn get(&self, index: usize) -> bool { let (byte_index, bit_mask) = self.get_indexes(index); - return self.data[byte_index] & bit_mask != 0; + self.data[byte_index] & bit_mask != 0 } /// Sets all bits to the specified value @@ -86,7 +86,7 @@ impl BitVec { let byte_index = index / 8; let bit_in_byte_index = 7 - index % 8; let bit_mask: u8 = 1 << bit_in_byte_index; - return (byte_index, bit_mask); + (byte_index, bit_mask) } } diff --git a/servicepoint2/src/command.rs b/servicepoint2/src/command.rs index 6a8e02a..7708be3 100644 --- a/servicepoint2/src/command.rs +++ b/servicepoint2/src/command.rs @@ -273,7 +273,7 @@ fn command_code_only(code: CommandCode) -> Packet { /// Helper method for checking that a packet is empty and only contains a command code fn check_command_only(packet: Packet) -> Option { let Packet(Header(_, a, b, c, d), payload) = packet; - if payload.len() != 0 { + if !payload.is_empty() { Some(TryFromPacketError::UnexpectedPayloadSize(0, payload.len())) } else if a != 0 || b != 0 || c != 0 || d != 0 { Some(TryFromPacketError::ExtraneousHeaderValues) @@ -322,7 +322,7 @@ pub mod c_api pub unsafe extern "C" fn sp2_command_try_from_packet(packet: *mut Packet) -> *mut Command { let packet = *Box::from_raw(packet); match Command::try_from(packet) { - Err(_) => return null_mut(), + Err(_) => null_mut(), Ok(command) => Box::into_raw(Box::new(command)), } } diff --git a/servicepoint2/src/compression.rs b/servicepoint2/src/compression.rs index 0fd0df7..c651a1b 100644 --- a/servicepoint2/src/compression.rs +++ b/servicepoint2/src/compression.rs @@ -93,7 +93,7 @@ pub(crate) fn into_compressed( let mut encoder = Lz4EncoderBuilder::new() .build(vec![]) .expect("could not create encoder"); - encoder.write(&*payload).expect("could not write payload"); + encoder.write(&payload).expect("could not write payload"); let (payload, _) = encoder.finish(); payload } @@ -103,7 +103,7 @@ pub(crate) fn into_compressed( ZstdEncoder::new(vec![], zstd::DEFAULT_COMPRESSION_LEVEL) .expect("could not create encoder"); encoder - .write(&*payload) + .write(&payload) .expect("could not compress payload"); encoder.finish().expect("could not finish encoding") } diff --git a/servicepoint2/src/connection.rs b/servicepoint2/src/connection.rs index d8656ce..ba57234 100644 --- a/servicepoint2/src/connection.rs +++ b/servicepoint2/src/connection.rs @@ -58,9 +58,8 @@ impl Connection { packet: Packet, ) -> Result<(), std::io::Error> { debug!("sending {packet:?}"); - let packet: Packet = packet.into(); let data: Vec = packet.into(); - self.socket.send(&*data)?; + self.socket.send(&data)?; Ok(()) } } diff --git a/servicepoint2/src/packet.rs b/servicepoint2/src/packet.rs index 1d1b0ca..e144bf9 100644 --- a/servicepoint2/src/packet.rs +++ b/servicepoint2/src/packet.rs @@ -17,15 +17,15 @@ impl From for Vec { let Packet(Header(mode, a, b, c, d), payload) = value; let mut packet = vec![0u8; 10 + payload.len()]; - packet[0..=1].copy_from_slice(&u16::to_be_bytes(mode.into())); + packet[0..=1].copy_from_slice(&u16::to_be_bytes(mode)); packet[2..=3].copy_from_slice(&u16::to_be_bytes(a)); packet[4..=5].copy_from_slice(&u16::to_be_bytes(b)); packet[6..=7].copy_from_slice(&u16::to_be_bytes(c)); packet[8..=9].copy_from_slice(&u16::to_be_bytes(d)); - packet[10..].copy_from_slice(&*payload); + packet[10..].copy_from_slice(&payload); - return packet; + packet } }