1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-05-05 10:09:07 +00:00

Merge pull request #61 from Luro02/master

Fix a lot of clippy lints
This commit is contained in:
Lucas 2020-08-11 11:14:13 +02:00 committed by GitHub
commit 68453ea54d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 49 additions and 48 deletions

View file

@ -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
)]

View file

@ -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") {

View file

@ -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()

View file

@ -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(_) => {}
}
}

View file

@ -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,

View file

@ -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(),
}
}

View file

@ -122,7 +122,7 @@ impl<'a> ExtInf<'a> {
/// 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 {
self.title = value.map(|v| v.into());
self.title = value.map(Into::into);
self
}

View file

@ -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

View file

@ -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(),
}
}
}

View file

@ -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()
);

View file

@ -67,7 +67,7 @@ where
{
fn from(value: Vec<T>) -> 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) {

View file

@ -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());

View file

@ -52,7 +52,7 @@ impl InitializationVector {
/// assert_eq!(InitializationVector::Missing.to_u128(), None);
/// ```
#[must_use]
pub fn to_u128(&self) -> Option<u128> {
pub const fn to_u128(&self) -> Option<u128> {
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()),

View file

@ -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.
///

View file

@ -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())),

View file

@ -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;