From 832be80dcbaddb26ae97ab87ec7af0b8009f2a4b Mon Sep 17 00:00:00 2001 From: David Holroyd Date: Mon, 11 Mar 2024 22:36:15 +0000 Subject: [PATCH] Fix clippy lints --- src/builder.rs | 21 +++++++++++++-------- src/lib.rs | 2 +- src/reader.rs | 6 +++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index fb5f8ff..05a4c31 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -97,6 +97,12 @@ pub struct RtpPacketBuilder<'a> { csrc_count: u8, } +impl<'a> Default for RtpPacketBuilder<'a> { + fn default() -> Self { + Self::new() + } +} + impl<'a> RtpPacketBuilder<'a> { /// Create a new RTP packet builder pub fn new() -> Self { @@ -154,7 +160,7 @@ impl<'a> RtpPacketBuilder<'a> { self } else { self.csrcs[self.csrc_count as usize] = csrc; - self.csrc_count = self.csrc_count + 1; + self.csrc_count += 1; self } } @@ -256,23 +262,23 @@ impl<'a> RtpPacketBuilder<'a> { let mut write_index = 12usize; for index in 0..self.csrc_count as usize { let csrc = self.csrcs[index]; - target[write_index + 0] = (csrc >> 24) as u8; + target[write_index] = (csrc >> 24) as u8; target[write_index + 1] = (csrc >> 16) as u8; target[write_index + 2] = (csrc >> 8) as u8; target[write_index + 3] = (csrc) as u8; - write_index = write_index + 4; + write_index += 4; } if let Some((id, payload)) = self.extension { - target[write_index + 0] = (id >> 8) as u8; + target[write_index] = (id >> 8) as u8; target[write_index + 1] = (id & 0xFF) as u8; let len = payload.len() / 4; target[write_index + 2] = (len >> 8) as u8; target[write_index + 3] = (len & 0xFF) as u8; - write_index = write_index + 4; + write_index += 4; /* the target buffer has been ensured to hold that many bytes */ target[write_index..(write_index + payload.len())].copy_from_slice(payload); @@ -307,12 +313,11 @@ impl<'a> RtpPacketBuilder<'a> { } /// Build the RTP packet. - /// On success it returns a buffer containing the target packet. + /// On success, it returns a buffer containing the target packet. pub fn build(&self) -> Result, RtpPacketBuildError> { self.validate_content()?; - let mut buffer = Vec::::new(); - buffer.resize(self.target_length(), 0); + let mut buffer = vec![0; self.target_length()]; let length = self.build_into_unchecked(buffer.as_mut_slice()); assert_eq!(length, buffer.len()); diff --git a/src/lib.rs b/src/lib.rs index 050a2e7..718524a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -120,7 +120,7 @@ impl std::ops::Sub for Seq { } impl PartialOrd for Seq { fn partial_cmp(&self, other: &Seq) -> Option { - (*self - *other).partial_cmp(&0) + Some(self.cmp(other)) } } impl Ord for Seq { diff --git a/src/reader.rs b/src/reader.rs index 0e401c2..ea75097 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -397,14 +397,14 @@ mod tests { let reader = RtpReader::new(&TEST_RTP_PACKET).unwrap(); let buffer = reader.create_builder().build().unwrap(); - assert_eq!(&buffer.as_slice()[..], &TEST_RTP_PACKET[..]); + assert_eq!(buffer.as_slice(), &TEST_RTP_PACKET[..]); } #[test] fn builder_juggle_extension() { let reader = RtpReader::new(&TEST_RTP_PACKET_WITH_EXTENSION).unwrap(); let buffer = reader.create_builder().build().unwrap(); - assert_eq!(&buffer.as_slice()[..], &TEST_RTP_PACKET_WITH_EXTENSION[..]); + assert_eq!(buffer.as_slice(), &TEST_RTP_PACKET_WITH_EXTENSION[..]); } #[test] @@ -418,7 +418,7 @@ mod tests { .unwrap(); let expected = &TEST_RTP_PACKET_WITH_EXTENSION[0..(3 + 4) * 4]; - assert_eq!(&buffer.as_slice()[..], expected); + assert_eq!(buffer.as_slice(), expected); } #[test]