clippy fix

This commit is contained in:
Vinzenz Schroeter 2024-05-15 23:08:54 +02:00
parent 8a68de8895
commit b0de3a4fb5
5 changed files with 11 additions and 12 deletions

View file

@ -39,7 +39,7 @@ impl BitVec {
byte & (u8::MAX ^ bit_mask) byte & (u8::MAX ^ bit_mask)
}; };
return old_value; old_value
} }
/// Gets the value of a bit. /// Gets the value of a bit.
@ -51,7 +51,7 @@ impl BitVec {
/// returns: value of the bit /// returns: value of the bit
pub fn get(&self, index: usize) -> bool { pub fn get(&self, index: usize) -> bool {
let (byte_index, bit_mask) = self.get_indexes(index); 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 /// Sets all bits to the specified value
@ -86,7 +86,7 @@ impl BitVec {
let byte_index = index / 8; let byte_index = index / 8;
let bit_in_byte_index = 7 - index % 8; let bit_in_byte_index = 7 - index % 8;
let bit_mask: u8 = 1 << bit_in_byte_index; let bit_mask: u8 = 1 << bit_in_byte_index;
return (byte_index, bit_mask); (byte_index, bit_mask)
} }
} }

View file

@ -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 /// Helper method for checking that a packet is empty and only contains a command code
fn check_command_only(packet: Packet) -> Option<TryFromPacketError> { fn check_command_only(packet: Packet) -> Option<TryFromPacketError> {
let Packet(Header(_, a, b, c, d), payload) = packet; let Packet(Header(_, a, b, c, d), payload) = packet;
if payload.len() != 0 { if !payload.is_empty() {
Some(TryFromPacketError::UnexpectedPayloadSize(0, payload.len())) Some(TryFromPacketError::UnexpectedPayloadSize(0, payload.len()))
} else if a != 0 || b != 0 || c != 0 || d != 0 { } else if a != 0 || b != 0 || c != 0 || d != 0 {
Some(TryFromPacketError::ExtraneousHeaderValues) 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 { pub unsafe extern "C" fn sp2_command_try_from_packet(packet: *mut Packet) -> *mut Command {
let packet = *Box::from_raw(packet); let packet = *Box::from_raw(packet);
match Command::try_from(packet) { match Command::try_from(packet) {
Err(_) => return null_mut(), Err(_) => null_mut(),
Ok(command) => Box::into_raw(Box::new(command)), Ok(command) => Box::into_raw(Box::new(command)),
} }
} }

View file

@ -93,7 +93,7 @@ pub(crate) fn into_compressed(
let mut encoder = Lz4EncoderBuilder::new() let mut encoder = Lz4EncoderBuilder::new()
.build(vec![]) .build(vec![])
.expect("could not create encoder"); .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(); let (payload, _) = encoder.finish();
payload payload
} }
@ -103,7 +103,7 @@ pub(crate) fn into_compressed(
ZstdEncoder::new(vec![], zstd::DEFAULT_COMPRESSION_LEVEL) ZstdEncoder::new(vec![], zstd::DEFAULT_COMPRESSION_LEVEL)
.expect("could not create encoder"); .expect("could not create encoder");
encoder encoder
.write(&*payload) .write(&payload)
.expect("could not compress payload"); .expect("could not compress payload");
encoder.finish().expect("could not finish encoding") encoder.finish().expect("could not finish encoding")
} }

View file

@ -58,9 +58,8 @@ impl Connection {
packet: Packet, packet: Packet,
) -> Result<(), std::io::Error> { ) -> Result<(), std::io::Error> {
debug!("sending {packet:?}"); debug!("sending {packet:?}");
let packet: Packet = packet.into();
let data: Vec<u8> = packet.into(); let data: Vec<u8> = packet.into();
self.socket.send(&*data)?; self.socket.send(&data)?;
Ok(()) Ok(())
} }
} }

View file

@ -17,15 +17,15 @@ impl From<Packet> for Vec<u8> {
let Packet(Header(mode, a, b, c, d), payload) = value; let Packet(Header(mode, a, b, c, d), payload) = value;
let mut packet = vec![0u8; 10 + payload.len()]; 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[2..=3].copy_from_slice(&u16::to_be_bytes(a));
packet[4..=5].copy_from_slice(&u16::to_be_bytes(b)); packet[4..=5].copy_from_slice(&u16::to_be_bytes(b));
packet[6..=7].copy_from_slice(&u16::to_be_bytes(c)); packet[6..=7].copy_from_slice(&u16::to_be_bytes(c));
packet[8..=9].copy_from_slice(&u16::to_be_bytes(d)); 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
} }
} }