From aee8e215ca93a5f6d4af3b7374a678e431eadfce Mon Sep 17 00:00:00 2001 From: tact1m4n3 Date: Sat, 18 May 2024 13:22:19 +0300 Subject: [PATCH] fix: solve clippy warnings --- src/lib.rs | 15 +++++++-------- src/packets/link_statistics.rs | 2 +- src/packets/mod.rs | 7 ++++--- src/packets/rc_channels_packed.rs | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 243eb91..6184eaa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,9 +22,9 @@ //! let channels: [u16; 16] = [0xffff; 16]; //! let addr = PacketAddress::FlightController; //! let payload = RcChannelsPacked(channels); -//! +//! //! // Import the `Payload` trait to construct a raw packet -//! let raw_packet = payload.into_raw_packet_with_sync(addr as u8).unwrap(); +//! let raw_packet = payload.to_raw_packet_with_sync(addr as u8).unwrap(); //! // ... //! ``` @@ -492,7 +492,6 @@ mod tests { #[test] fn test_push_segments() { // similar to the doc-test at the top - let mut reader = PacketReader::new(); let data: &[&[u8]] = &[&[0xc8, 24, 0x16], &[0; 22], &[239]]; for (i, input_buf) in data.iter().enumerate() { @@ -514,17 +513,17 @@ mod tests { let rc_channels1 = RcChannelsPacked([1000; 16]); let raw_packet1 = rc_channels1 - .into_raw_packet_with_sync(PacketAddress::FlightController as u8) + .to_raw_packet_with_sync(PacketAddress::FlightController as u8) .unwrap(); let rc_channels2 = RcChannelsPacked([1500; 16]); let raw_packet2 = rc_channels2 - .into_raw_packet_with_sync(PacketAddress::Broadcast as u8) + .to_raw_packet_with_sync(PacketAddress::Broadcast as u8) .unwrap(); let rc_channels3 = RcChannelsPacked([2000; 16]); // Some other address here ---v let raw_packet3 = rc_channels3 - .into_raw_packet_with_sync(PacketAddress::Reserved1 as u8) + .to_raw_packet_with_sync(PacketAddress::Reserved1 as u8) .unwrap(); let result1 = reader @@ -644,7 +643,7 @@ mod tests { let addr = PacketAddress::Transmitter; let packet = RcChannelsPacked(channels); - let raw = packet.into_raw_packet_with_sync(addr as u8).unwrap(); + let raw = packet.to_raw_packet_with_sync(addr as u8).unwrap(); let mut expected_data: [u8; 26] = [0xff; 26]; expected_data[0] = 0xee; @@ -671,7 +670,7 @@ mod tests { downlink_snr: -108, }; - let raw = packet.into_raw_packet_with_sync(addr as u8).unwrap(); + let raw = packet.to_raw_packet_with_sync(addr as u8).unwrap(); let expected_data = [0xc8, 12, 0x14, 16, 19, 99, 151, 1, 2, 3, 8, 88, 148, 252]; assert_eq!(raw.as_slice(), expected_data.as_slice()) diff --git a/src/packets/link_statistics.rs b/src/packets/link_statistics.rs index 5327f0b..b4a0c92 100644 --- a/src/packets/link_statistics.rs +++ b/src/packets/link_statistics.rs @@ -94,7 +94,7 @@ mod tests { downlink_snr: -68, }; - let raw = original.into_raw_packet().unwrap(); + let raw = original.to_raw_packet().unwrap(); let data = raw.payload().unwrap(); diff --git a/src/packets/mod.rs b/src/packets/mod.rs index 830037e..4bb2abc 100644 --- a/src/packets/mod.rs +++ b/src/packets/mod.rs @@ -11,6 +11,7 @@ pub use link_statistics::LinkStatistics; /// A trait encapsulationg a CRSF payload. This trait is used to encode and decode payloads /// to and from byte slices, as well as convert into a [`RawPacket`]s for transmitting elsewhere. +#[allow(clippy::len_without_is_empty)] pub trait Payload where Self: Sized, @@ -34,15 +35,15 @@ where /// Construct a new `RawPacket` from a `Packet`. This adds the `sync`, `len`, `type` bytes, /// and calculates and adds the `crc` byte. This constructor assumes the given packet is valid. - fn into_raw_packet(&self) -> Result { - self.into_raw_packet_with_sync(CRSF_SYNC_BYTE) + fn to_raw_packet(&self) -> Result { + self.to_raw_packet_with_sync(CRSF_SYNC_BYTE) } /// Construct a new `RawPacket` from a `Packet`. This adds the given `sync` byte, `len`, `type` bytes, /// and calculates and adds the `crc` byte. This constructor assumes the given packet is valid. /// Note that changing the sync byte is not officially supported by the CRSF protocol, but is used /// in some implementations as an "address" byte. - fn into_raw_packet_with_sync(&self, sync_byte: u8) -> Result { + fn to_raw_packet_with_sync(&self, sync_byte: u8) -> Result { let mut raw = RawPacket { buf: [0u8; CRSF_MAX_LEN], len: 4 + Self::LEN, diff --git a/src/packets/rc_channels_packed.rs b/src/packets/rc_channels_packed.rs index 2b5b72b..a1677a7 100644 --- a/src/packets/rc_channels_packed.rs +++ b/src/packets/rc_channels_packed.rs @@ -99,7 +99,7 @@ mod tests { 983, 992, 174, 992, 191, 191, 191, 191, 997, 997, 997, 997, 0, 0, 1811, 1811, ]); - let raw = original.into_raw_packet().unwrap(); + let raw = original.to_raw_packet().unwrap(); let data = raw.payload().unwrap();