From c2c94f9352d943f1395e8d74ac6707e981592030 Mon Sep 17 00:00:00 2001 From: Lucas <24826124+Luro02@users.noreply.github.com> Date: Fri, 1 Oct 2021 13:04:57 +0200 Subject: [PATCH] fix clippy lints --- src/master_playlist.rs | 16 +++++----------- src/media_playlist.rs | 11 +++++------ src/tags/master_playlist/session_data.rs | 4 ++-- src/tags/master_playlist/variant_stream.rs | 2 +- src/tags/media_segment/date_range.rs | 8 ++++---- src/types/byte_range.rs | 8 +++----- src/types/float.rs | 2 +- src/types/key_format_versions.rs | 18 ++++-------------- src/types/stream_data.rs | 4 ++-- src/types/ufloat.rs | 2 +- src/utils.rs | 6 +----- 11 files changed, 29 insertions(+), 52 deletions(-) diff --git a/src/master_playlist.rs b/src/master_playlist.rs index 34855bd..a74e725 100644 --- a/src/master_playlist.rs +++ b/src/master_playlist.rs @@ -220,13 +220,9 @@ impl<'a> MasterPlaylist<'a> { /// Returns all streams, which have an audio group id. pub fn audio_streams(&self) -> impl Iterator> { - self.variant_streams.iter().filter(|stream| { - if let VariantStream::ExtXStreamInf { audio: Some(_), .. } = stream { - true - } else { - false - } - }) + self.variant_streams + .iter() + .filter(|stream| matches!(stream, VariantStream::ExtXStreamInf { audio: Some(_), .. })) } /// Returns all streams, which have a video group id. @@ -416,13 +412,11 @@ impl<'a> MasterPlaylistBuilder<'a> { } fn check_media_group>(&self, media_type: MediaType, group_id: T) -> bool { - if let Some(value) = &self.media { + self.media.as_ref().map_or(false, |value| { value.iter().any(|media| { media.media_type == media_type && media.group_id().as_ref() == group_id.as_ref() }) - } else { - false - } + }) } } diff --git a/src/media_playlist.rs b/src/media_playlist.rs index bf3ff39..cae7120 100644 --- a/src/media_playlist.rs +++ b/src/media_playlist.rs @@ -315,12 +315,11 @@ impl<'a> MediaPlaylistBuilder<'a> { method, iv, format, .. })) = key { - if *method == EncryptionMethod::Aes128 && *iv == InitializationVector::Missing { - if format.is_none() { - *iv = InitializationVector::Number(segment.number as u128); - } else if let Some(KeyFormat::Identity) = format { - *iv = InitializationVector::Number(segment.number as u128); - } + if *method == EncryptionMethod::Aes128 + && *iv == InitializationVector::Missing + && (format.is_none() || &mut Some(KeyFormat::Identity) == format) + { + *iv = InitializationVector::Number(segment.number as u128); } } } diff --git a/src/tags/master_playlist/session_data.rs b/src/tags/master_playlist/session_data.rs index 937bf2f..688d73b 100644 --- a/src/tags/master_playlist/session_data.rs +++ b/src/tags/master_playlist/session_data.rs @@ -223,9 +223,9 @@ impl<'a> TryFrom<&'a str> for ExtXSessionData<'a> { if let Some(value) = session_value { if uri.is_some() { return Err(Error::custom("unexpected URI")); - } else { - SessionData::Value(value) } + + SessionData::Value(value) } else if let Some(uri) = uri { SessionData::Uri(uri) } else { diff --git a/src/tags/master_playlist/variant_stream.rs b/src/tags/master_playlist/variant_stream.rs index 21f72f4..21e910c 100644 --- a/src/tags/master_playlist/variant_stream.rs +++ b/src/tags/master_playlist/variant_stream.rs @@ -379,7 +379,7 @@ impl<'a> TryFrom<&'a str> for VariantStream<'a> { "AUDIO" => audio = Some(unquote(value)), "SUBTITLES" => subtitles = Some(unquote(value)), "CLOSED-CAPTIONS" => { - closed_captions = Some(ClosedCaptions::try_from(value).unwrap()) + closed_captions = Some(ClosedCaptions::try_from(value).unwrap()); } _ => {} } diff --git a/src/tags/media_segment/date_range.rs b/src/tags/media_segment/date_range.rs index bc37939..0536ca4 100644 --- a/src/tags/media_segment/date_range.rs +++ b/src/tags/media_segment/date_range.rs @@ -380,21 +380,21 @@ impl<'a> TryFrom<&'a str> for ExtXDateRange<'a> { "START-DATE" => { #[cfg(feature = "chrono")] { - start_date = Some(unquote(value).parse().map_err(Error::chrono)?) + start_date = Some(unquote(value).parse().map_err(Error::chrono)?); } #[cfg(not(feature = "chrono"))] { - start_date = Some(unquote(value)) + start_date = Some(unquote(value)); } } "END-DATE" => { #[cfg(feature = "chrono")] { - end_date = Some(unquote(value).parse().map_err(Error::chrono)?) + end_date = Some(unquote(value).parse().map_err(Error::chrono)?); } #[cfg(not(feature = "chrono"))] { - end_date = Some(unquote(value)) + end_date = Some(unquote(value)); } } "DURATION" => { diff --git a/src/types/byte_range.rs b/src/types/byte_range.rs index 672886e..b300d9f 100644 --- a/src/types/byte_range.rs +++ b/src/types/byte_range.rs @@ -354,11 +354,9 @@ impl_from_ranges![u64, u32, u16, u8, usize, i32]; #[must_use] impl RangeBounds for ByteRange { fn start_bound(&self) -> Bound<&usize> { - if let Some(start) = &self.start { - Bound::Included(start) - } else { - Bound::Unbounded - } + self.start + .as_ref() + .map_or(Bound::Unbounded, Bound::Included) } #[inline] diff --git a/src/types/float.rs b/src/types/float.rs index 57261e7..5ac2ccd 100644 --- a/src/types/float.rs +++ b/src/types/float.rs @@ -182,7 +182,7 @@ impl ::core::hash::Hash for Float { } else { // I do not think it matters to differentiate between architectures, that use // big endian by default and those, that use little endian. - state.write(&self.to_be_bytes()) + state.write(&self.to_be_bytes()); } } } diff --git a/src/types/key_format_versions.rs b/src/types/key_format_versions.rs index 518c7c5..61763d9 100644 --- a/src/types/key_format_versions.rs +++ b/src/types/key_format_versions.rs @@ -36,7 +36,7 @@ use crate::RequiredVersion; /// ``` /// /// [`KeyFormat`]: crate::types::KeyFormat -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Default)] pub struct KeyFormatVersions { // NOTE(Luro02): if the current array is not big enough one can easily increase // the number of elements or change the type to something bigger, @@ -295,7 +295,7 @@ impl Extend for KeyFormatVersions { impl<'a> Extend<&'a u8> for KeyFormatVersions { fn extend>(&mut self, iter: I) { - >::extend(self, iter.into_iter().copied()) + >::extend(self, iter.into_iter().copied()); } } @@ -346,17 +346,7 @@ impl FromIterator for KeyFormatVersions { impl<'a> FromIterator<&'a u8> for KeyFormatVersions { fn from_iter>(iter: I) -> Self { - >::from_iter(iter.into_iter().copied()) - } -} - -impl Default for KeyFormatVersions { - #[inline] - fn default() -> Self { - Self { - buffer: [0; 9], - len: 0, - } + iter.into_iter().copied().collect() } } @@ -413,7 +403,7 @@ impl fmt::Display for KeyFormatVersions { } impl> From for KeyFormatVersions { - fn from(value: T) -> Self { Self::from_iter(value.as_ref().iter().map(|i| *i as u8)) } + fn from(value: T) -> Self { value.as_ref().iter().map(|i| *i as u8).collect() } } /// `Iterator` for [`KeyFormatVersions`]. diff --git a/src/types/stream_data.rs b/src/types/stream_data.rs index bb7d70a..162c99c 100644 --- a/src/types/stream_data.rs +++ b/src/types/stream_data.rs @@ -323,12 +323,12 @@ impl<'a> TryFrom<&'a str> for StreamData<'a> { value .parse::() .map_err(|e| Error::parse_int(value, e))?, - ) + ); } "CODECS" => codecs = Some(TryFrom::try_from(unquote(value))?), "RESOLUTION" => resolution = Some(value.parse()?), "HDCP-LEVEL" => { - hdcp_level = Some(value.parse::().map_err(Error::strum)?) + hdcp_level = Some(value.parse::().map_err(Error::strum)?); } "VIDEO" => video = Some(unquote(value)), _ => { diff --git a/src/types/ufloat.rs b/src/types/ufloat.rs index d4a0d57..d22947e 100644 --- a/src/types/ufloat.rs +++ b/src/types/ufloat.rs @@ -193,7 +193,7 @@ impl ::core::hash::Hash for UFloat { // I do not think it matters to differentiate between architectures, that use // big endian by default and those, that use little endian. - state.write(&self.to_be_bytes()) + state.write(&self.to_be_bytes()); } } diff --git a/src/utils.rs b/src/utils.rs index 345fa63..cb162df 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -73,11 +73,7 @@ pub(crate) fn unquote(value: &str) -> Cow<'_, str> { if value.starts_with('"') && value.ends_with('"') { let result = Cow::Borrowed(&value[1..value.len() - 1]); - if result - .chars() - .find(|c| *c == '"' || *c == '\n' || *c == '\r') - .is_none() - { + if !result.chars().any(|c| c == '"' || c == '\n' || c == '\r') { return result; } }