Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings added over the last 3 years #74

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#![doc(html_root_url = "https://docs.rs/hls_m3u8/0.4.1")]
#![forbid(unsafe_code)]
#![warn(rust_2018_idioms)]
#![warn(
clippy::pedantic, //
clippy::nursery,
clippy::cargo,
clippy::inline_always,
)]
#![warn(clippy::cargo, clippy::inline_always)]
#![allow(
clippy::non_ascii_literal,
clippy::redundant_pub_crate,
Expand All @@ -19,10 +14,10 @@
clippy::clone_on_ref_ptr,
clippy::decimal_literal_representation,
clippy::get_unwrap,
clippy::expect_used,
clippy::unneeded_field_pattern,
clippy::wrong_pub_self_convention
clippy::wrong_self_convention
)]
#![cfg_attr(not(test), warn(clippy::expect_used))]
// those should not be present in production code:
#![deny(
clippy::print_stdout,
Expand Down
34 changes: 17 additions & 17 deletions src/master_playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use crate::{Error, RequiredVersion};
/// closed_captions: None,
/// stream_data: StreamData::builder()
/// .bandwidth(150000)
/// .codecs(&["avc1.42e00a", "mp4a.40.2"])
/// .codecs(["avc1.42e00a", "mp4a.40.2"])
/// .resolution((416, 234))
/// .build()
/// .unwrap(),
Expand All @@ -81,7 +81,7 @@ use crate::{Error, RequiredVersion};
/// closed_captions: None,
/// stream_data: StreamData::builder()
/// .bandwidth(240000)
/// .codecs(&["avc1.42e00a", "mp4a.40.2"])
/// .codecs(["avc1.42e00a", "mp4a.40.2"])
/// .resolution((416, 234))
/// .build()
/// .unwrap(),
Expand Down Expand Up @@ -190,7 +190,7 @@ impl<'a> MasterPlaylist<'a> {
/// closed_captions: None,
/// stream_data: StreamData::builder()
/// .bandwidth(150000)
/// .codecs(&["avc1.42e00a", "mp4a.40.2"])
/// .codecs(["avc1.42e00a", "mp4a.40.2"])
/// .resolution((416, 234))
/// .build()
/// .unwrap(),
Expand All @@ -203,7 +203,7 @@ impl<'a> MasterPlaylist<'a> {
/// closed_captions: None,
/// stream_data: StreamData::builder()
/// .bandwidth(240000)
/// .codecs(&["avc1.42e00a", "mp4a.40.2"])
/// .codecs(["avc1.42e00a", "mp4a.40.2"])
/// .resolution((416, 234))
/// .build()
/// .unwrap(),
Expand Down Expand Up @@ -262,7 +262,7 @@ impl<'a> MasterPlaylist<'a> {
pub fn associated_with<'b>(
&'b self,
stream: &'b VariantStream<'_>,
) -> impl Iterator<Item = &ExtXMedia<'a>> + 'b {
) -> impl Iterator<Item = &'b ExtXMedia<'a>> + 'b {
self.media
.iter()
.filter(move |media| stream.is_associated(media))
Expand Down Expand Up @@ -576,7 +576,7 @@ mod tests {
closed_captions: None,
stream_data: StreamData::builder()
.bandwidth(150_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"])
.codecs(["avc1.42e00a", "mp4a.40.2"])
.resolution((416, 234))
.build()
.unwrap(),
Expand All @@ -589,7 +589,7 @@ mod tests {
closed_captions: None,
stream_data: StreamData::builder()
.bandwidth(240_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"])
.codecs(["avc1.42e00a", "mp4a.40.2"])
.resolution((416, 234))
.build()
.unwrap(),
Expand Down Expand Up @@ -662,7 +662,7 @@ mod tests {
closed_captions: None,
stream_data: StreamData::builder()
.bandwidth(150_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"])
.codecs(["avc1.42e00a", "mp4a.40.2"])
.resolution((416, 234))
.build()
.unwrap()
Expand All @@ -675,7 +675,7 @@ mod tests {
closed_captions: None,
stream_data: StreamData::builder()
.bandwidth(240_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"])
.codecs(["avc1.42e00a", "mp4a.40.2"])
.resolution((416, 234))
.build()
.unwrap()
Expand All @@ -688,7 +688,7 @@ mod tests {
closed_captions: None,
stream_data: StreamData::builder()
.bandwidth(440_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"])
.codecs(["avc1.42e00a", "mp4a.40.2"])
.resolution((416, 234))
.build()
.unwrap()
Expand All @@ -701,7 +701,7 @@ mod tests {
closed_captions: None,
stream_data: StreamData::builder()
.bandwidth(640_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"])
.codecs(["avc1.42e00a", "mp4a.40.2"])
.resolution((640, 360))
.build()
.unwrap()
Expand All @@ -714,7 +714,7 @@ mod tests {
closed_captions: None,
stream_data: StreamData::builder()
.bandwidth(64000)
.codecs(&["mp4a.40.5"])
.codecs(["mp4a.40.5"])
.build()
.unwrap()
},
Expand All @@ -737,7 +737,7 @@ mod tests {
closed_captions: None,
stream_data: StreamData::builder()
.bandwidth(150_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"])
.codecs(["avc1.42e00a", "mp4a.40.2"])
.resolution((416, 234))
.build()
.unwrap()
Expand All @@ -750,7 +750,7 @@ mod tests {
closed_captions: None,
stream_data: StreamData::builder()
.bandwidth(240_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"])
.codecs(["avc1.42e00a", "mp4a.40.2"])
.resolution((416, 234))
.build()
.unwrap()
Expand All @@ -763,7 +763,7 @@ mod tests {
closed_captions: None,
stream_data: StreamData::builder()
.bandwidth(440_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"])
.codecs(["avc1.42e00a", "mp4a.40.2"])
.resolution((416, 234))
.build()
.unwrap()
Expand All @@ -776,7 +776,7 @@ mod tests {
closed_captions: None,
stream_data: StreamData::builder()
.bandwidth(640_000)
.codecs(&["avc1.42e00a", "mp4a.40.2"])
.codecs(["avc1.42e00a", "mp4a.40.2"])
.resolution((640, 360))
.build()
.unwrap()
Expand All @@ -789,7 +789,7 @@ mod tests {
closed_captions: None,
stream_data: StreamData::builder()
.bandwidth(64000)
.codecs(&["mp4a.40.5"])
.codecs(["mp4a.40.5"])
.build()
.unwrap()
},
Expand Down
4 changes: 2 additions & 2 deletions src/media_playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct MediaPlaylist<'a> {
/// - [`PlaylistType::Vod`] indicates that the playlist must not change.
///
/// - [`PlaylistType::Event`] indicates that the server does not change or
/// delete any part of the playlist, but may append new lines to it.
/// delete any part of the playlist, but may append new lines to it.
///
/// ### Note
///
Expand Down Expand Up @@ -367,7 +367,7 @@ impl<'a> MediaPlaylistBuilder<'a> {
allowable_excess_duration: self
.allowable_excess_duration
.unwrap_or_else(|| Duration::from_secs(0)),
unknown: self.unknown.clone().unwrap_or_else(Vec::new),
unknown: self.unknown.clone().unwrap_or_default(),
})
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/tags/basic/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{Error, RequiredVersion};
///
/// [`MediaPlaylist`]: crate::MediaPlaylist
/// [`MasterPlaylist`]: crate::MasterPlaylist
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct ExtXVersion(ProtocolVersion);

impl ExtXVersion {
Expand Down Expand Up @@ -59,10 +59,6 @@ impl fmt::Display for ExtXVersion {
}
}

impl Default for ExtXVersion {
fn default() -> Self { Self(ProtocolVersion::default()) }
}

impl From<ProtocolVersion> for ExtXVersion {
fn from(value: ProtocolVersion) -> Self { Self(value) }
}
Expand Down
34 changes: 12 additions & 22 deletions src/tags/master_playlist/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct ExtXMedia<'a> {
/// - This field is required, if the [`ExtXMedia::media_type`] is
/// [`MediaType::Subtitles`].
/// - This field is not allowed, if the [`ExtXMedia::media_type`] is
/// [`MediaType::ClosedCaptions`].
/// [`MediaType::ClosedCaptions`].
///
/// An absent value indicates that the media data for this rendition is
/// included in the [`MediaPlaylist`] of any
Expand Down Expand Up @@ -138,8 +138,8 @@ pub struct ExtXMedia<'a> {
/// following characteristics:
/// - `"public.accessibility.transcribes-spoken-dialog"`,
/// - `"public.accessibility.describes-music-and-sound"`, and
/// - `"public.easy-to-read"` (which indicates that the subtitles have
/// been edited for ease of reading).
/// - `"public.easy-to-read"` (which indicates that the subtitles have been
/// edited for ease of reading).
///
/// An `ExtXMedia` instance with [`MediaType::Audio`] may include the
/// following characteristic:
Expand Down Expand Up @@ -745,28 +745,18 @@ mod test {

#[test]
fn test_parser_error() {
assert_eq!(ExtXMedia::try_from("").is_err(), true);
assert_eq!(ExtXMedia::try_from("garbage").is_err(), true);
assert!(ExtXMedia::try_from("").is_err());
assert!(ExtXMedia::try_from("garbage").is_err());

assert_eq!(
ExtXMedia::try_from("#EXT-X-MEDIA:TYPE=CLOSED-CAPTIONS,URI=\"http://www.example.com\"")
.is_err(),
true
);
assert_eq!(
ExtXMedia::try_from("#EXT-X-MEDIA:TYPE=AUDIO,INSTREAM-ID=CC1").is_err(),
true
);
assert!(ExtXMedia::try_from(
"#EXT-X-MEDIA:TYPE=CLOSED-CAPTIONS,URI=\"http://www.example.com\""
)
.is_err());
assert!(ExtXMedia::try_from("#EXT-X-MEDIA:TYPE=AUDIO,INSTREAM-ID=CC1").is_err());

assert_eq!(
ExtXMedia::try_from("#EXT-X-MEDIA:TYPE=AUDIO,DEFAULT=YES,AUTOSELECT=NO").is_err(),
true
);
assert!(ExtXMedia::try_from("#EXT-X-MEDIA:TYPE=AUDIO,DEFAULT=YES,AUTOSELECT=NO").is_err());

assert_eq!(
ExtXMedia::try_from("#EXT-X-MEDIA:TYPE=AUDIO,FORCED=YES").is_err(),
true
);
assert!(ExtXMedia::try_from("#EXT-X-MEDIA:TYPE=AUDIO,FORCED=YES").is_err());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/tags/master_playlist/session_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<'a> RequiredVersion for ExtXSessionKey<'a> {

impl<'a> fmt::Display for ExtXSessionKey<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}{}", Self::PREFIX, self.0.to_string())
write!(f, "{}{}", Self::PREFIX, self.0)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/tags/media_segment/byte_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl RequiredVersion for ExtXByteRange {
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V4 }
}

#[allow(clippy::from_over_into)] // Some magic `From` blanket impl is going on that means this can't be done.
impl Into<ByteRange> for ExtXByteRange {
fn into(self) -> ByteRange { self.0 }
}
Expand Down
4 changes: 2 additions & 2 deletions src/tags/media_segment/date_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ impl<'a> fmt::Display for ExtXDateRange<'a> {

#[cfg(not(feature = "chrono"))]
{
write!(f, ",START-DATE={}", quote(&value))?;
write!(f, ",START-DATE={}", quote(value))?;
}
}

Expand All @@ -518,7 +518,7 @@ impl<'a> fmt::Display for ExtXDateRange<'a> {

#[cfg(not(feature = "chrono"))]
{
write!(f, ",END-DATE={}", quote(&value))?;
write!(f, ",END-DATE={}", quote(value))?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tags/media_segment/inf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl<'a> TryFrom<&'a str> for ExtInf<'a> {
.next()
.map(str::trim)
.filter(|value| !value.is_empty())
.map(|v| Cow::Borrowed(v));
.map(Cow::Borrowed);

Ok(Self { duration, title })
}
Expand Down
Loading
Loading