mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-18 10:00:14 +01:00
clippy fix
This commit is contained in:
parent
8a68de8895
commit
b0de3a4fb5
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<TryFromPacketError> {
|
||||
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)),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -58,9 +58,8 @@ impl Connection {
|
|||
packet: Packet,
|
||||
) -> Result<(), std::io::Error> {
|
||||
debug!("sending {packet:?}");
|
||||
let packet: Packet = packet.into();
|
||||
let data: Vec<u8> = packet.into();
|
||||
self.socket.send(&*data)?;
|
||||
self.socket.send(&data)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,15 +17,15 @@ impl From<Packet> for Vec<u8> {
|
|||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue