diff --git a/src/lib.rs b/src/lib.rs index ec31b4a..6657ef2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,8 @@ clippy::inline_always, )] #![allow( + clippy::non_ascii_literal, + clippy::redundant_pub_crate, clippy::multiple_crate_versions, clippy::module_name_repetitions, clippy::default_trait_access, @@ -17,7 +19,7 @@ clippy::clone_on_ref_ptr, clippy::decimal_literal_representation, clippy::get_unwrap, - clippy::option_expect_used, + clippy::expect_used, clippy::unneeded_field_pattern, clippy::wrong_pub_self_convention )] diff --git a/src/line.rs b/src/line.rs index 3603933..0112936 100644 --- a/src/line.rs +++ b/src/line.rs @@ -23,7 +23,7 @@ impl<'a> Iterator for Lines<'a> { Some( tags::VariantStream::try_from(format!("{}\n{}", line, uri).as_str()) - .map(|v| v.into_owned()) + .map(tags::VariantStream::into_owned) .map(|v| Line::Tag(Tag::VariantStream(v))), ) } else if line.starts_with("#EXT") { diff --git a/src/master_playlist.rs b/src/master_playlist.rs index efd73d6..34855bd 100644 --- a/src/master_playlist.rs +++ b/src/master_playlist.rs @@ -279,6 +279,7 @@ impl<'a> MasterPlaylist<'a> { /// /// This is a relatively expensive operation. #[must_use] + #[allow(clippy::redundant_closure_for_method_calls)] pub fn into_owned(self) -> MasterPlaylist<'static> { MasterPlaylist { has_independent_segments: self.has_independent_segments, @@ -550,7 +551,7 @@ impl<'a> TryFrom<&'a str> for MasterPlaylist<'a> { Line::Uri(uri) => { return Err(Error::custom(format!("unexpected uri: {:?}", uri))); } - _ => {} + Line::Comment(_) => {} } } @@ -580,7 +581,7 @@ mod tests { subtitles: None, closed_captions: None, stream_data: StreamData::builder() - .bandwidth(150000) + .bandwidth(150_000) .codecs(&["avc1.42e00a", "mp4a.40.2"]) .resolution((416, 234)) .build() @@ -593,7 +594,7 @@ mod tests { subtitles: None, closed_captions: None, stream_data: StreamData::builder() - .bandwidth(240000) + .bandwidth(240_000) .codecs(&["avc1.42e00a", "mp4a.40.2"]) .resolution((416, 234)) .build() @@ -666,7 +667,7 @@ mod tests { subtitles: None, closed_captions: None, stream_data: StreamData::builder() - .bandwidth(150000) + .bandwidth(150_000) .codecs(&["avc1.42e00a", "mp4a.40.2"]) .resolution((416, 234)) .build() @@ -679,7 +680,7 @@ mod tests { subtitles: None, closed_captions: None, stream_data: StreamData::builder() - .bandwidth(240000) + .bandwidth(240_000) .codecs(&["avc1.42e00a", "mp4a.40.2"]) .resolution((416, 234)) .build() @@ -692,7 +693,7 @@ mod tests { subtitles: None, closed_captions: None, stream_data: StreamData::builder() - .bandwidth(440000) + .bandwidth(440_000) .codecs(&["avc1.42e00a", "mp4a.40.2"]) .resolution((416, 234)) .build() @@ -705,7 +706,7 @@ mod tests { subtitles: None, closed_captions: None, stream_data: StreamData::builder() - .bandwidth(640000) + .bandwidth(640_000) .codecs(&["avc1.42e00a", "mp4a.40.2"]) .resolution((640, 360)) .build() @@ -741,7 +742,7 @@ mod tests { subtitles: None, closed_captions: None, stream_data: StreamData::builder() - .bandwidth(150000) + .bandwidth(150_000) .codecs(&["avc1.42e00a", "mp4a.40.2"]) .resolution((416, 234)) .build() @@ -754,7 +755,7 @@ mod tests { subtitles: None, closed_captions: None, stream_data: StreamData::builder() - .bandwidth(240000) + .bandwidth(240_000) .codecs(&["avc1.42e00a", "mp4a.40.2"]) .resolution((416, 234)) .build() @@ -767,7 +768,7 @@ mod tests { subtitles: None, closed_captions: None, stream_data: StreamData::builder() - .bandwidth(440000) + .bandwidth(440_000) .codecs(&["avc1.42e00a", "mp4a.40.2"]) .resolution((416, 234)) .build() @@ -780,7 +781,7 @@ mod tests { subtitles: None, closed_captions: None, stream_data: StreamData::builder() - .bandwidth(640000) + .bandwidth(640_000) .codecs(&["avc1.42e00a", "mp4a.40.2"]) .resolution((640, 360)) .build() diff --git a/src/media_playlist.rs b/src/media_playlist.rs index 5dc5e2a..0ef8e7d 100644 --- a/src/media_playlist.rs +++ b/src/media_playlist.rs @@ -350,7 +350,7 @@ impl<'a> MediaPlaylistBuilder<'a> { // .enumerate() // .find_map(|(i, e)| e.is_none().athen(i)) // .unwrap(); - return Err(format!("a segment is missing")); + return Err("a segment is missing".to_string()); } Ok(MediaPlaylist { @@ -710,7 +710,7 @@ fn parse_media_playlist<'a>( segment = MediaSegment::builder(); has_partial_segment = false; } - _ => {} + Line::Comment(_) => {} } } diff --git a/src/media_segment.rs b/src/media_segment.rs index 7213ef9..b79ad66 100644 --- a/src/media_segment.rs +++ b/src/media_segment.rs @@ -183,6 +183,7 @@ impl<'a> MediaSegment<'a> { /// /// This is a relatively expensive operation. #[must_use] + #[allow(clippy::redundant_closure_for_method_calls)] pub fn into_owned(self) -> MediaSegment<'static> { MediaSegment { number: self.number, diff --git a/src/tags/master_playlist/variant_stream.rs b/src/tags/master_playlist/variant_stream.rs index 19e6c76..21f72f4 100644 --- a/src/tags/master_playlist/variant_stream.rs +++ b/src/tags/master_playlist/variant_stream.rs @@ -268,7 +268,7 @@ impl<'a> VariantStream<'a> { frame_rate, audio: audio.map(|v| Cow::Owned(v.into_owned())), subtitles: subtitles.map(|v| Cow::Owned(v.into_owned())), - closed_captions: closed_captions.map(|v| v.into_owned()), + closed_captions: closed_captions.map(ClosedCaptions::into_owned), stream_data: stream_data.into_owned(), } } diff --git a/src/tags/media_segment/inf.rs b/src/tags/media_segment/inf.rs index b8abcdd..f8278cc 100644 --- a/src/tags/media_segment/inf.rs +++ b/src/tags/media_segment/inf.rs @@ -122,7 +122,7 @@ impl<'a> ExtInf<'a> { /// assert_eq!(ext_inf.title(), &Some("better title".into())); /// ``` pub fn set_title>>(&mut self, value: Option) -> &mut Self { - self.title = value.map(|v| v.into()); + self.title = value.map(Into::into); self } diff --git a/src/tags/media_segment/key.rs b/src/tags/media_segment/key.rs index 98e8cf4..74549ea 100644 --- a/src/tags/media_segment/key.rs +++ b/src/tags/media_segment/key.rs @@ -172,7 +172,7 @@ impl<'a> ExtXKey<'a> { /// [`Cow`]: std::borrow::Cow #[must_use] #[inline] - pub fn into_owned(self) -> ExtXKey<'static> { ExtXKey(self.0.map(|v| v.into_owned())) } + pub fn into_owned(self) -> ExtXKey<'static> { ExtXKey(self.0.map(DecryptionKey::into_owned)) } } /// This tag requires [`ProtocolVersion::V5`], if [`KeyFormat`] or diff --git a/src/tags/media_segment/map.rs b/src/tags/media_segment/map.rs index 17e7130..e344871 100644 --- a/src/tags/media_segment/map.rs +++ b/src/tags/media_segment/map.rs @@ -95,7 +95,7 @@ impl<'a> ExtXMap<'a> { ExtXMap { uri: Cow::Owned(self.uri.into_owned()), range: self.range, - keys: self.keys.into_iter().map(|v| v.into_owned()).collect(), + keys: self.keys.into_iter().map(ExtXKey::into_owned).collect(), } } } diff --git a/src/types/byte_range.rs b/src/types/byte_range.rs index 084db4c..672886e 100644 --- a/src/types/byte_range.rs +++ b/src/types/byte_range.rs @@ -447,10 +447,12 @@ mod tests { #[test] #[should_panic = "the range start (6) must be smaller than the end (0)"] + #[allow(clippy::reversed_empty_ranges)] fn test_from_range_panic() { let _ = ByteRange::from(6..0); } #[test] #[should_panic = "the range start (6) must be smaller than the end (0+1)"] + #[allow(clippy::reversed_empty_ranges)] fn test_from_range_inclusive_panic() { let _ = ByteRange::from(6..=0); } #[test] @@ -516,6 +518,7 @@ mod tests { fn test_set_start() { let _ = ByteRange::from(4..10).set_start(Some(11)); } #[test] + #[allow(clippy::identity_op)] fn test_add() { // normal addition assert_eq!(ByteRange::from(5..10) + 5, ByteRange::from(10..15)); @@ -531,6 +534,7 @@ mod tests { fn test_add_panic() { let _ = ByteRange::from(usize::max_value()..usize::max_value()) + 1; } #[test] + #[allow(clippy::identity_op)] fn test_sub() { // normal subtraction assert_eq!(ByteRange::from(5..10) - 4, ByteRange::from(1..6)); @@ -658,7 +662,7 @@ mod tests { assert_eq!(ByteRange::from(0..5).to_string(), "5@0".to_string()); assert_eq!( - ByteRange::from(2..100001).to_string(), + ByteRange::from(2..100_001).to_string(), "99999@2".to_string() ); diff --git a/src/types/codecs.rs b/src/types/codecs.rs index 0e44425..c425f0b 100644 --- a/src/types/codecs.rs +++ b/src/types/codecs.rs @@ -67,7 +67,7 @@ where { fn from(value: Vec) -> Self { Self { - list: value.into_iter().map(|v| v.into()).collect(), + list: value.into_iter().map(Into::into).collect(), } } } @@ -76,6 +76,7 @@ where macro_rules! implement_from { ($($size:expr),*) => { $( + #[allow(clippy::reversed_empty_ranges)] impl<'a> From<[&'a str; $size]> for Codecs<'a> { fn from(value: [&'a str; $size]) -> Self { Self { @@ -92,6 +93,7 @@ macro_rules! implement_from { } } + #[allow(clippy::reversed_empty_ranges)] impl<'a> From<&[&'a str; $size]> for Codecs<'a> { fn from(value: &[&'a str; $size]) -> Self { Self { @@ -119,7 +121,7 @@ implement_from!( impl<'a> fmt::Display for Codecs<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if let Some(codec) = self.list.iter().next() { + if let Some(codec) = self.list.first() { write!(f, "{}", codec)?; for codec in self.list.iter().skip(1) { diff --git a/src/types/float.rs b/src/types/float.rs index 7e2a8d9..25ed85a 100644 --- a/src/types/float.rs +++ b/src/types/float.rs @@ -188,6 +188,9 @@ mod tests { use core::hash::{Hash, Hasher}; use pretty_assertions::assert_eq; + #[allow(clippy::all, clippy::unreadable_literal)] + const PI: f32 = 3.14159265359; + #[test] fn test_ord() { assert_eq!(Float::new(1.1).cmp(&Float::new(1.1)), Ordering::Equal); @@ -235,7 +238,7 @@ mod tests { } #[test] - fn test_eq() { + const fn test_eq() { struct _AssertEq where Float: Eq; @@ -251,24 +254,15 @@ mod tests { #[test] fn test_display() { assert_eq!(Float::new(22.0).to_string(), "22".to_string()); - assert_eq!( - Float::new(3.14159265359).to_string(), - "3.1415927".to_string() - ); - assert_eq!( - Float::new(-3.14159265359).to_string(), - "-3.1415927".to_string() - ); + assert_eq!(Float::new(PI).to_string(), "3.1415927".to_string()); + assert_eq!(Float::new(-PI).to_string(), "-3.1415927".to_string()); } #[test] fn test_parser() { assert_eq!(Float::new(22.0), Float::from_str("22").unwrap()); assert_eq!(Float::new(-22.0), Float::from_str("-22").unwrap()); - assert_eq!( - Float::new(3.14159265359), - Float::from_str("3.14159265359").unwrap() - ); + assert_eq!(Float::new(PI), Float::from_str("3.14159265359").unwrap()); assert!(Float::from_str("1#").is_err()); assert!(Float::from_str("NaN").is_err()); assert!(Float::from_str("inf").is_err()); diff --git a/src/types/initialization_vector.rs b/src/types/initialization_vector.rs index 779d3f1..24bb213 100644 --- a/src/types/initialization_vector.rs +++ b/src/types/initialization_vector.rs @@ -52,7 +52,7 @@ impl InitializationVector { /// assert_eq!(InitializationVector::Missing.to_u128(), None); /// ``` #[must_use] - pub fn to_u128(&self) -> Option { + pub const fn to_u128(&self) -> Option { match *self { Self::Aes128(v) => Some(u128::from_be_bytes(v)), Self::Number(n) => Some(n), @@ -93,7 +93,7 @@ impl InitializationVector { /// /// [`MediaSegment`]: crate::MediaSegment #[must_use] - pub fn to_slice(&self) -> Option<[u8; 0x10]> { + pub const fn to_slice(&self) -> Option<[u8; 0x10]> { match &self { Self::Aes128(v) => Some(*v), Self::Number(v) => Some(v.to_be_bytes()), diff --git a/src/types/key_format_versions.rs b/src/types/key_format_versions.rs index 518c7c5..b5f5980 100644 --- a/src/types/key_format_versions.rs +++ b/src/types/key_format_versions.rs @@ -144,7 +144,7 @@ impl KeyFormatVersions { /// the future this number might increase. #[inline] #[must_use] - pub fn capacity(&self) -> usize { self.buffer.len() } + pub const fn capacity(&self) -> usize { self.buffer.len() } /// Shortens the internal array to the provided length. /// diff --git a/src/types/stream_data.rs b/src/types/stream_data.rs index 28b5314..bb7d70a 100644 --- a/src/types/stream_data.rs +++ b/src/types/stream_data.rs @@ -267,7 +267,7 @@ impl<'a> StreamData<'a> { StreamData { bandwidth: self.bandwidth, average_bandwidth: self.average_bandwidth, - codecs: self.codecs.map(|v| v.into_owned()), + codecs: self.codecs.map(Codecs::into_owned), resolution: self.resolution, hdcp_level: self.hdcp_level, video: self.video.map(|v| Cow::Owned(v.into_owned())), diff --git a/src/types/ufloat.rs b/src/types/ufloat.rs index 25cb13f..08f4a5e 100644 --- a/src/types/ufloat.rs +++ b/src/types/ufloat.rs @@ -198,22 +198,19 @@ mod tests { use core::hash::{Hash, Hasher}; use pretty_assertions::assert_eq; + #[allow(clippy::all, clippy::unreadable_literal)] + const PI: f32 = 3.14159265359; + #[test] fn test_display() { assert_eq!(UFloat::new(22.0).to_string(), "22".to_string()); - assert_eq!( - UFloat::new(3.14159265359).to_string(), - "3.1415927".to_string() - ); + assert_eq!(UFloat::new(PI).to_string(), "3.1415927".to_string()); } #[test] fn test_parser() { assert_eq!(UFloat::new(22.0), UFloat::from_str("22").unwrap()); - assert_eq!( - UFloat::new(3.14159265359), - UFloat::from_str("3.14159265359").unwrap() - ); + assert_eq!(UFloat::new(PI), UFloat::from_str("3.14159265359").unwrap()); assert!(UFloat::from_str("1#").is_err()); assert!(UFloat::from_str("-1.0").is_err()); assert!(UFloat::from_str("NaN").is_err()); @@ -309,7 +306,7 @@ mod tests { } #[test] - fn test_eq() { + const fn test_eq() { struct _AssertEq where UFloat: Eq;