1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-11-25 08:31:00 +00:00

Merge pull request #68 from Luro02/clippy

fix clippy lints
This commit is contained in:
Lucas 2021-10-01 13:36:57 +02:00 committed by GitHub
commit 9ec0687f5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 29 additions and 52 deletions

View file

@ -220,13 +220,9 @@ impl<'a> MasterPlaylist<'a> {
/// Returns all streams, which have an audio group id. /// Returns all streams, which have an audio group id.
pub fn audio_streams(&self) -> impl Iterator<Item = &VariantStream<'a>> { pub fn audio_streams(&self) -> impl Iterator<Item = &VariantStream<'a>> {
self.variant_streams.iter().filter(|stream| { self.variant_streams
if let VariantStream::ExtXStreamInf { audio: Some(_), .. } = stream { .iter()
true .filter(|stream| matches!(stream, VariantStream::ExtXStreamInf { audio: Some(_), .. }))
} else {
false
}
})
} }
/// Returns all streams, which have a video group id. /// Returns all streams, which have a video group id.
@ -416,13 +412,11 @@ impl<'a> MasterPlaylistBuilder<'a> {
} }
fn check_media_group<T: AsRef<str>>(&self, media_type: MediaType, group_id: T) -> bool { fn check_media_group<T: AsRef<str>>(&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| { value.iter().any(|media| {
media.media_type == media_type && media.group_id().as_ref() == group_id.as_ref() media.media_type == media_type && media.group_id().as_ref() == group_id.as_ref()
}) })
} else { })
false
}
} }
} }

View file

@ -315,12 +315,11 @@ impl<'a> MediaPlaylistBuilder<'a> {
method, iv, format, .. method, iv, format, ..
})) = key })) = key
{ {
if *method == EncryptionMethod::Aes128 && *iv == InitializationVector::Missing { if *method == EncryptionMethod::Aes128
if format.is_none() { && *iv == InitializationVector::Missing
*iv = InitializationVector::Number(segment.number as u128); && (format.is_none() || &mut Some(KeyFormat::Identity) == format)
} else if let Some(KeyFormat::Identity) = format { {
*iv = InitializationVector::Number(segment.number as u128); *iv = InitializationVector::Number(segment.number as u128);
}
} }
} }
} }

View file

@ -223,9 +223,9 @@ impl<'a> TryFrom<&'a str> for ExtXSessionData<'a> {
if let Some(value) = session_value { if let Some(value) = session_value {
if uri.is_some() { if uri.is_some() {
return Err(Error::custom("unexpected URI")); return Err(Error::custom("unexpected URI"));
} else {
SessionData::Value(value)
} }
SessionData::Value(value)
} else if let Some(uri) = uri { } else if let Some(uri) = uri {
SessionData::Uri(uri) SessionData::Uri(uri)
} else { } else {

View file

@ -379,7 +379,7 @@ impl<'a> TryFrom<&'a str> for VariantStream<'a> {
"AUDIO" => audio = Some(unquote(value)), "AUDIO" => audio = Some(unquote(value)),
"SUBTITLES" => subtitles = Some(unquote(value)), "SUBTITLES" => subtitles = Some(unquote(value)),
"CLOSED-CAPTIONS" => { "CLOSED-CAPTIONS" => {
closed_captions = Some(ClosedCaptions::try_from(value).unwrap()) closed_captions = Some(ClosedCaptions::try_from(value).unwrap());
} }
_ => {} _ => {}
} }

View file

@ -380,21 +380,21 @@ impl<'a> TryFrom<&'a str> for ExtXDateRange<'a> {
"START-DATE" => { "START-DATE" => {
#[cfg(feature = "chrono")] #[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"))] #[cfg(not(feature = "chrono"))]
{ {
start_date = Some(unquote(value)) start_date = Some(unquote(value));
} }
} }
"END-DATE" => { "END-DATE" => {
#[cfg(feature = "chrono")] #[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"))] #[cfg(not(feature = "chrono"))]
{ {
end_date = Some(unquote(value)) end_date = Some(unquote(value));
} }
} }
"DURATION" => { "DURATION" => {

View file

@ -354,11 +354,9 @@ impl_from_ranges![u64, u32, u16, u8, usize, i32];
#[must_use] #[must_use]
impl RangeBounds<usize> for ByteRange { impl RangeBounds<usize> for ByteRange {
fn start_bound(&self) -> Bound<&usize> { fn start_bound(&self) -> Bound<&usize> {
if let Some(start) = &self.start { self.start
Bound::Included(start) .as_ref()
} else { .map_or(Bound::Unbounded, Bound::Included)
Bound::Unbounded
}
} }
#[inline] #[inline]

View file

@ -182,7 +182,7 @@ impl ::core::hash::Hash for Float {
} else { } else {
// I do not think it matters to differentiate between architectures, that use // I do not think it matters to differentiate between architectures, that use
// big endian by default and those, that use little endian. // big endian by default and those, that use little endian.
state.write(&self.to_be_bytes()) state.write(&self.to_be_bytes());
} }
} }
} }

View file

@ -36,7 +36,7 @@ use crate::RequiredVersion;
/// ``` /// ```
/// ///
/// [`KeyFormat`]: crate::types::KeyFormat /// [`KeyFormat`]: crate::types::KeyFormat
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy, Default)]
pub struct KeyFormatVersions { pub struct KeyFormatVersions {
// NOTE(Luro02): if the current array is not big enough one can easily increase // 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, // the number of elements or change the type to something bigger,
@ -295,7 +295,7 @@ impl Extend<u8> for KeyFormatVersions {
impl<'a> Extend<&'a u8> for KeyFormatVersions { impl<'a> Extend<&'a u8> for KeyFormatVersions {
fn extend<I: IntoIterator<Item = &'a u8>>(&mut self, iter: I) { fn extend<I: IntoIterator<Item = &'a u8>>(&mut self, iter: I) {
<Self as Extend<u8>>::extend(self, iter.into_iter().copied()) <Self as Extend<u8>>::extend(self, iter.into_iter().copied());
} }
} }
@ -346,17 +346,7 @@ impl FromIterator<u8> for KeyFormatVersions {
impl<'a> FromIterator<&'a u8> for KeyFormatVersions { impl<'a> FromIterator<&'a u8> for KeyFormatVersions {
fn from_iter<I: IntoIterator<Item = &'a u8>>(iter: I) -> Self { fn from_iter<I: IntoIterator<Item = &'a u8>>(iter: I) -> Self {
<Self as FromIterator<u8>>::from_iter(iter.into_iter().copied()) iter.into_iter().copied().collect()
}
}
impl Default for KeyFormatVersions {
#[inline]
fn default() -> Self {
Self {
buffer: [0; 9],
len: 0,
}
} }
} }
@ -413,7 +403,7 @@ impl fmt::Display for KeyFormatVersions {
} }
impl<T: AsRef<[usize]>> From<T> for KeyFormatVersions { impl<T: AsRef<[usize]>> From<T> 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`]. /// `Iterator` for [`KeyFormatVersions`].

View file

@ -323,12 +323,12 @@ impl<'a> TryFrom<&'a str> for StreamData<'a> {
value value
.parse::<u64>() .parse::<u64>()
.map_err(|e| Error::parse_int(value, e))?, .map_err(|e| Error::parse_int(value, e))?,
) );
} }
"CODECS" => codecs = Some(TryFrom::try_from(unquote(value))?), "CODECS" => codecs = Some(TryFrom::try_from(unquote(value))?),
"RESOLUTION" => resolution = Some(value.parse()?), "RESOLUTION" => resolution = Some(value.parse()?),
"HDCP-LEVEL" => { "HDCP-LEVEL" => {
hdcp_level = Some(value.parse::<HdcpLevel>().map_err(Error::strum)?) hdcp_level = Some(value.parse::<HdcpLevel>().map_err(Error::strum)?);
} }
"VIDEO" => video = Some(unquote(value)), "VIDEO" => video = Some(unquote(value)),
_ => { _ => {

View file

@ -193,7 +193,7 @@ impl ::core::hash::Hash for UFloat {
// I do not think it matters to differentiate between architectures, that use // I do not think it matters to differentiate between architectures, that use
// big endian by default and those, that use little endian. // big endian by default and those, that use little endian.
state.write(&self.to_be_bytes()) state.write(&self.to_be_bytes());
} }
} }

View file

@ -73,11 +73,7 @@ pub(crate) fn unquote(value: &str) -> Cow<'_, str> {
if value.starts_with('"') && value.ends_with('"') { if value.starts_with('"') && value.ends_with('"') {
let result = Cow::Borrowed(&value[1..value.len() - 1]); let result = Cow::Borrowed(&value[1..value.len() - 1]);
if result if !result.chars().any(|c| c == '"' || c == '\n' || c == '\r') {
.chars()
.find(|c| *c == '"' || *c == '\n' || *c == '\r')
.is_none()
{
return result; return result;
} }
} }