Skip to content

Commit

Permalink
fix: solve clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tact1m4n3 committed May 18, 2024
1 parent a129e57 commit aee8e21
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
15 changes: 7 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
//! // ...
//! ```
Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/packets/link_statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
7 changes: 4 additions & 3 deletions src/packets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<RawPacket, CrsfError> {
self.into_raw_packet_with_sync(CRSF_SYNC_BYTE)
fn to_raw_packet(&self) -> Result<RawPacket, CrsfError> {
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<RawPacket, CrsfError> {
fn to_raw_packet_with_sync(&self, sync_byte: u8) -> Result<RawPacket, CrsfError> {
let mut raw = RawPacket {
buf: [0u8; CRSF_MAX_LEN],
len: 4 + Self::LEN,
Expand Down
2 changes: 1 addition & 1 deletion src/packets/rc_channels_packed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit aee8e21

Please sign in to comment.