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

Fix a lot of clippy lints

This commit is contained in:
Luro02 2020-08-11 11:13:14 +02:00
parent c343858860
commit e6588ab963
No known key found for this signature in database
GPG key ID: B66FD4F74501A9CF
16 changed files with 49 additions and 48 deletions

View file

@ -8,6 +8,8 @@
clippy::inline_always, clippy::inline_always,
)] )]
#![allow( #![allow(
clippy::non_ascii_literal,
clippy::redundant_pub_crate,
clippy::multiple_crate_versions, clippy::multiple_crate_versions,
clippy::module_name_repetitions, clippy::module_name_repetitions,
clippy::default_trait_access, clippy::default_trait_access,
@ -17,7 +19,7 @@
clippy::clone_on_ref_ptr, clippy::clone_on_ref_ptr,
clippy::decimal_literal_representation, clippy::decimal_literal_representation,
clippy::get_unwrap, clippy::get_unwrap,
clippy::option_expect_used, clippy::expect_used,
clippy::unneeded_field_pattern, clippy::unneeded_field_pattern,
clippy::wrong_pub_self_convention clippy::wrong_pub_self_convention
)] )]

View file

@ -23,7 +23,7 @@ impl<'a> Iterator for Lines<'a> {
Some( Some(
tags::VariantStream::try_from(format!("{}\n{}", line, uri).as_str()) 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))), .map(|v| Line::Tag(Tag::VariantStream(v))),
) )
} else if line.starts_with("#EXT") { } else if line.starts_with("#EXT") {

View file

@ -279,6 +279,7 @@ impl<'a> MasterPlaylist<'a> {
/// ///
/// This is a relatively expensive operation. /// This is a relatively expensive operation.
#[must_use] #[must_use]
#[allow(clippy::redundant_closure_for_method_calls)]
pub fn into_owned(self) -> MasterPlaylist<'static> { pub fn into_owned(self) -> MasterPlaylist<'static> {
MasterPlaylist { MasterPlaylist {
has_independent_segments: self.has_independent_segments, has_independent_segments: self.has_independent_segments,
@ -550,7 +551,7 @@ impl<'a> TryFrom<&'a str> for MasterPlaylist<'a> {
Line::Uri(uri) => { Line::Uri(uri) => {
return Err(Error::custom(format!("unexpected uri: {:?}", uri))); return Err(Error::custom(format!("unexpected uri: {:?}", uri)));
} }
_ => {} Line::Comment(_) => {}
} }
} }
@ -580,7 +581,7 @@ mod tests {
subtitles: None, subtitles: None,
closed_captions: None, closed_captions: None,
stream_data: StreamData::builder() stream_data: StreamData::builder()
.bandwidth(150000) .bandwidth(150_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"]) .codecs(&["avc1.42e00a", "mp4a.40.2"])
.resolution((416, 234)) .resolution((416, 234))
.build() .build()
@ -593,7 +594,7 @@ mod tests {
subtitles: None, subtitles: None,
closed_captions: None, closed_captions: None,
stream_data: StreamData::builder() stream_data: StreamData::builder()
.bandwidth(240000) .bandwidth(240_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"]) .codecs(&["avc1.42e00a", "mp4a.40.2"])
.resolution((416, 234)) .resolution((416, 234))
.build() .build()
@ -666,7 +667,7 @@ mod tests {
subtitles: None, subtitles: None,
closed_captions: None, closed_captions: None,
stream_data: StreamData::builder() stream_data: StreamData::builder()
.bandwidth(150000) .bandwidth(150_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"]) .codecs(&["avc1.42e00a", "mp4a.40.2"])
.resolution((416, 234)) .resolution((416, 234))
.build() .build()
@ -679,7 +680,7 @@ mod tests {
subtitles: None, subtitles: None,
closed_captions: None, closed_captions: None,
stream_data: StreamData::builder() stream_data: StreamData::builder()
.bandwidth(240000) .bandwidth(240_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"]) .codecs(&["avc1.42e00a", "mp4a.40.2"])
.resolution((416, 234)) .resolution((416, 234))
.build() .build()
@ -692,7 +693,7 @@ mod tests {
subtitles: None, subtitles: None,
closed_captions: None, closed_captions: None,
stream_data: StreamData::builder() stream_data: StreamData::builder()
.bandwidth(440000) .bandwidth(440_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"]) .codecs(&["avc1.42e00a", "mp4a.40.2"])
.resolution((416, 234)) .resolution((416, 234))
.build() .build()
@ -705,7 +706,7 @@ mod tests {
subtitles: None, subtitles: None,
closed_captions: None, closed_captions: None,
stream_data: StreamData::builder() stream_data: StreamData::builder()
.bandwidth(640000) .bandwidth(640_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"]) .codecs(&["avc1.42e00a", "mp4a.40.2"])
.resolution((640, 360)) .resolution((640, 360))
.build() .build()
@ -741,7 +742,7 @@ mod tests {
subtitles: None, subtitles: None,
closed_captions: None, closed_captions: None,
stream_data: StreamData::builder() stream_data: StreamData::builder()
.bandwidth(150000) .bandwidth(150_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"]) .codecs(&["avc1.42e00a", "mp4a.40.2"])
.resolution((416, 234)) .resolution((416, 234))
.build() .build()
@ -754,7 +755,7 @@ mod tests {
subtitles: None, subtitles: None,
closed_captions: None, closed_captions: None,
stream_data: StreamData::builder() stream_data: StreamData::builder()
.bandwidth(240000) .bandwidth(240_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"]) .codecs(&["avc1.42e00a", "mp4a.40.2"])
.resolution((416, 234)) .resolution((416, 234))
.build() .build()
@ -767,7 +768,7 @@ mod tests {
subtitles: None, subtitles: None,
closed_captions: None, closed_captions: None,
stream_data: StreamData::builder() stream_data: StreamData::builder()
.bandwidth(440000) .bandwidth(440_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"]) .codecs(&["avc1.42e00a", "mp4a.40.2"])
.resolution((416, 234)) .resolution((416, 234))
.build() .build()
@ -780,7 +781,7 @@ mod tests {
subtitles: None, subtitles: None,
closed_captions: None, closed_captions: None,
stream_data: StreamData::builder() stream_data: StreamData::builder()
.bandwidth(640000) .bandwidth(640_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"]) .codecs(&["avc1.42e00a", "mp4a.40.2"])
.resolution((640, 360)) .resolution((640, 360))
.build() .build()

View file

@ -350,7 +350,7 @@ impl<'a> MediaPlaylistBuilder<'a> {
// .enumerate() // .enumerate()
// .find_map(|(i, e)| e.is_none().athen(i)) // .find_map(|(i, e)| e.is_none().athen(i))
// .unwrap(); // .unwrap();
return Err(format!("a segment is missing")); return Err("a segment is missing".to_string());
} }
Ok(MediaPlaylist { Ok(MediaPlaylist {
@ -710,7 +710,7 @@ fn parse_media_playlist<'a>(
segment = MediaSegment::builder(); segment = MediaSegment::builder();
has_partial_segment = false; has_partial_segment = false;
} }
_ => {} Line::Comment(_) => {}
} }
} }

View file

@ -183,6 +183,7 @@ impl<'a> MediaSegment<'a> {
/// ///
/// This is a relatively expensive operation. /// This is a relatively expensive operation.
#[must_use] #[must_use]
#[allow(clippy::redundant_closure_for_method_calls)]
pub fn into_owned(self) -> MediaSegment<'static> { pub fn into_owned(self) -> MediaSegment<'static> {
MediaSegment { MediaSegment {
number: self.number, number: self.number,

View file

@ -268,7 +268,7 @@ impl<'a> VariantStream<'a> {
frame_rate, frame_rate,
audio: audio.map(|v| Cow::Owned(v.into_owned())), audio: audio.map(|v| Cow::Owned(v.into_owned())),
subtitles: subtitles.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(), stream_data: stream_data.into_owned(),
} }
} }

View file

@ -122,7 +122,7 @@ impl<'a> ExtInf<'a> {
/// assert_eq!(ext_inf.title(), &Some("better title".into())); /// assert_eq!(ext_inf.title(), &Some("better title".into()));
/// ``` /// ```
pub fn set_title<T: Into<Cow<'a, str>>>(&mut self, value: Option<T>) -> &mut Self { pub fn set_title<T: Into<Cow<'a, str>>>(&mut self, value: Option<T>) -> &mut Self {
self.title = value.map(|v| v.into()); self.title = value.map(Into::into);
self self
} }

View file

@ -172,7 +172,7 @@ impl<'a> ExtXKey<'a> {
/// [`Cow`]: std::borrow::Cow /// [`Cow`]: std::borrow::Cow
#[must_use] #[must_use]
#[inline] #[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 /// This tag requires [`ProtocolVersion::V5`], if [`KeyFormat`] or

View file

@ -95,7 +95,7 @@ impl<'a> ExtXMap<'a> {
ExtXMap { ExtXMap {
uri: Cow::Owned(self.uri.into_owned()), uri: Cow::Owned(self.uri.into_owned()),
range: self.range, range: self.range,
keys: self.keys.into_iter().map(|v| v.into_owned()).collect(), keys: self.keys.into_iter().map(ExtXKey::into_owned).collect(),
} }
} }
} }

View file

@ -447,10 +447,12 @@ mod tests {
#[test] #[test]
#[should_panic = "the range start (6) must be smaller than the end (0)"] #[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); } fn test_from_range_panic() { let _ = ByteRange::from(6..0); }
#[test] #[test]
#[should_panic = "the range start (6) must be smaller than the end (0+1)"] #[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); } fn test_from_range_inclusive_panic() { let _ = ByteRange::from(6..=0); }
#[test] #[test]
@ -516,6 +518,7 @@ mod tests {
fn test_set_start() { let _ = ByteRange::from(4..10).set_start(Some(11)); } fn test_set_start() { let _ = ByteRange::from(4..10).set_start(Some(11)); }
#[test] #[test]
#[allow(clippy::identity_op)]
fn test_add() { fn test_add() {
// normal addition // normal addition
assert_eq!(ByteRange::from(5..10) + 5, ByteRange::from(10..15)); 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; } fn test_add_panic() { let _ = ByteRange::from(usize::max_value()..usize::max_value()) + 1; }
#[test] #[test]
#[allow(clippy::identity_op)]
fn test_sub() { fn test_sub() {
// normal subtraction // normal subtraction
assert_eq!(ByteRange::from(5..10) - 4, ByteRange::from(1..6)); 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(0..5).to_string(), "5@0".to_string());
assert_eq!( assert_eq!(
ByteRange::from(2..100001).to_string(), ByteRange::from(2..100_001).to_string(),
"99999@2".to_string() "99999@2".to_string()
); );

View file

@ -67,7 +67,7 @@ where
{ {
fn from(value: Vec<T>) -> Self { fn from(value: Vec<T>) -> Self {
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 { macro_rules! implement_from {
($($size:expr),*) => { ($($size:expr),*) => {
$( $(
#[allow(clippy::reversed_empty_ranges)]
impl<'a> From<[&'a str; $size]> for Codecs<'a> { impl<'a> From<[&'a str; $size]> for Codecs<'a> {
fn from(value: [&'a str; $size]) -> Self { fn from(value: [&'a str; $size]) -> Self {
Self { Self {
@ -92,6 +93,7 @@ macro_rules! implement_from {
} }
} }
#[allow(clippy::reversed_empty_ranges)]
impl<'a> From<&[&'a str; $size]> for Codecs<'a> { impl<'a> From<&[&'a str; $size]> for Codecs<'a> {
fn from(value: &[&'a str; $size]) -> Self { fn from(value: &[&'a str; $size]) -> Self {
Self { Self {
@ -119,7 +121,7 @@ implement_from!(
impl<'a> fmt::Display for Codecs<'a> { impl<'a> fmt::Display for Codecs<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 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)?; write!(f, "{}", codec)?;
for codec in self.list.iter().skip(1) { for codec in self.list.iter().skip(1) {

View file

@ -188,6 +188,9 @@ mod tests {
use core::hash::{Hash, Hasher}; use core::hash::{Hash, Hasher};
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
#[allow(clippy::all, clippy::unreadable_literal)]
const PI: f32 = 3.14159265359;
#[test] #[test]
fn test_ord() { fn test_ord() {
assert_eq!(Float::new(1.1).cmp(&Float::new(1.1)), Ordering::Equal); assert_eq!(Float::new(1.1).cmp(&Float::new(1.1)), Ordering::Equal);
@ -235,7 +238,7 @@ mod tests {
} }
#[test] #[test]
fn test_eq() { const fn test_eq() {
struct _AssertEq struct _AssertEq
where where
Float: Eq; Float: Eq;
@ -251,24 +254,15 @@ mod tests {
#[test] #[test]
fn test_display() { fn test_display() {
assert_eq!(Float::new(22.0).to_string(), "22".to_string()); assert_eq!(Float::new(22.0).to_string(), "22".to_string());
assert_eq!( assert_eq!(Float::new(PI).to_string(), "3.1415927".to_string());
Float::new(3.14159265359).to_string(), assert_eq!(Float::new(-PI).to_string(), "-3.1415927".to_string());
"3.1415927".to_string()
);
assert_eq!(
Float::new(-3.14159265359).to_string(),
"-3.1415927".to_string()
);
} }
#[test] #[test]
fn test_parser() { 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(-22.0), Float::from_str("-22").unwrap()); assert_eq!(Float::new(-22.0), Float::from_str("-22").unwrap());
assert_eq!( assert_eq!(Float::new(PI), Float::from_str("3.14159265359").unwrap());
Float::new(3.14159265359),
Float::from_str("3.14159265359").unwrap()
);
assert!(Float::from_str("1#").is_err()); assert!(Float::from_str("1#").is_err());
assert!(Float::from_str("NaN").is_err()); assert!(Float::from_str("NaN").is_err());
assert!(Float::from_str("inf").is_err()); assert!(Float::from_str("inf").is_err());

View file

@ -52,7 +52,7 @@ impl InitializationVector {
/// assert_eq!(InitializationVector::Missing.to_u128(), None); /// assert_eq!(InitializationVector::Missing.to_u128(), None);
/// ``` /// ```
#[must_use] #[must_use]
pub fn to_u128(&self) -> Option<u128> { pub const fn to_u128(&self) -> Option<u128> {
match *self { match *self {
Self::Aes128(v) => Some(u128::from_be_bytes(v)), Self::Aes128(v) => Some(u128::from_be_bytes(v)),
Self::Number(n) => Some(n), Self::Number(n) => Some(n),
@ -93,7 +93,7 @@ impl InitializationVector {
/// ///
/// [`MediaSegment`]: crate::MediaSegment /// [`MediaSegment`]: crate::MediaSegment
#[must_use] #[must_use]
pub fn to_slice(&self) -> Option<[u8; 0x10]> { pub const fn to_slice(&self) -> Option<[u8; 0x10]> {
match &self { match &self {
Self::Aes128(v) => Some(*v), Self::Aes128(v) => Some(*v),
Self::Number(v) => Some(v.to_be_bytes()), Self::Number(v) => Some(v.to_be_bytes()),

View file

@ -144,7 +144,7 @@ impl KeyFormatVersions {
/// the future this number might increase. /// the future this number might increase.
#[inline] #[inline]
#[must_use] #[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. /// Shortens the internal array to the provided length.
/// ///

View file

@ -267,7 +267,7 @@ impl<'a> StreamData<'a> {
StreamData { StreamData {
bandwidth: self.bandwidth, bandwidth: self.bandwidth,
average_bandwidth: self.average_bandwidth, average_bandwidth: self.average_bandwidth,
codecs: self.codecs.map(|v| v.into_owned()), codecs: self.codecs.map(Codecs::into_owned),
resolution: self.resolution, resolution: self.resolution,
hdcp_level: self.hdcp_level, hdcp_level: self.hdcp_level,
video: self.video.map(|v| Cow::Owned(v.into_owned())), video: self.video.map(|v| Cow::Owned(v.into_owned())),

View file

@ -198,22 +198,19 @@ mod tests {
use core::hash::{Hash, Hasher}; use core::hash::{Hash, Hasher};
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
#[allow(clippy::all, clippy::unreadable_literal)]
const PI: f32 = 3.14159265359;
#[test] #[test]
fn test_display() { fn test_display() {
assert_eq!(UFloat::new(22.0).to_string(), "22".to_string()); assert_eq!(UFloat::new(22.0).to_string(), "22".to_string());
assert_eq!( assert_eq!(UFloat::new(PI).to_string(), "3.1415927".to_string());
UFloat::new(3.14159265359).to_string(),
"3.1415927".to_string()
);
} }
#[test] #[test]
fn test_parser() { fn test_parser() {
assert_eq!(UFloat::new(22.0), UFloat::from_str("22").unwrap()); assert_eq!(UFloat::new(22.0), UFloat::from_str("22").unwrap());
assert_eq!( assert_eq!(UFloat::new(PI), UFloat::from_str("3.14159265359").unwrap());
UFloat::new(3.14159265359),
UFloat::from_str("3.14159265359").unwrap()
);
assert!(UFloat::from_str("1#").is_err()); assert!(UFloat::from_str("1#").is_err());
assert!(UFloat::from_str("-1.0").is_err()); assert!(UFloat::from_str("-1.0").is_err());
assert!(UFloat::from_str("NaN").is_err()); assert!(UFloat::from_str("NaN").is_err());
@ -309,7 +306,7 @@ mod tests {
} }
#[test] #[test]
fn test_eq() { const fn test_eq() {
struct _AssertEq struct _AssertEq
where where
UFloat: Eq; UFloat: Eq;