diff --git a/Cargo.toml b/Cargo.toml index e05780a..f71b574 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ readme = "README.md" license = "MIT" keywords = ["hls", "m3u8"] edition = "2018" +categories = ["parser"] [badges] travis-ci = {repository = "sile/hls_m3u8"} @@ -18,4 +19,4 @@ codecov = {repository = "sile/hls_m3u8"} trackable = "0.2" [dev-dependencies] -clap = "2" \ No newline at end of file +clap = "2" diff --git a/src/lib.rs b/src/lib.rs index 889d757..409ba59 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,8 @@ +#![warn( + //clippy::pedantic, + clippy::nursery, + clippy::cargo +)] //! [HLS] m3u8 parser/generator. //! //! [HLS]: https://tools.ietf.org/html/rfc8216 diff --git a/src/line.rs b/src/line.rs index 6b1b1f6..974d01d 100644 --- a/src/line.rs +++ b/src/line.rs @@ -9,7 +9,7 @@ pub struct Lines<'a> { input: &'a str, } impl<'a> Lines<'a> { - pub fn new(input: &'a str) -> Self { + pub const fn new(input: &'a str) -> Self { Lines { input } } diff --git a/src/master_playlist.rs b/src/master_playlist.rs index 40fc065..48a4453 100644 --- a/src/master_playlist.rs +++ b/src/master_playlist.rs @@ -238,17 +238,17 @@ pub struct MasterPlaylist { impl MasterPlaylist { /// Returns the `EXT-X-VERSION` tag contained in the playlist. - pub fn version_tag(&self) -> ExtXVersion { + pub const fn version_tag(&self) -> ExtXVersion { self.version_tag } /// Returns the `EXT-X-INDEPENDENT-SEGMENTS` tag contained in the playlist. - pub fn independent_segments_tag(&self) -> Option { + pub const fn independent_segments_tag(&self) -> Option { self.independent_segments_tag } /// Returns the `EXT-X-START` tag contained in the playlist. - pub fn start_tag(&self) -> Option { + pub const fn start_tag(&self) -> Option { self.start_tag } diff --git a/src/media_playlist.rs b/src/media_playlist.rs index a25d816..2f5b7a4 100644 --- a/src/media_playlist.rs +++ b/src/media_playlist.rs @@ -27,6 +27,7 @@ pub struct MediaPlaylistBuilder { segments: Vec, options: MediaPlaylistOptions, } + impl MediaPlaylistBuilder { /// Makes a new `MediaPlaylistBuilder` instance. pub fn new() -> Self { @@ -180,6 +181,7 @@ impl MediaPlaylistBuilder { .unwrap_or(ProtocolVersion::V1) } } + impl Default for MediaPlaylistBuilder { fn default() -> Self { Self::new() @@ -200,49 +202,50 @@ pub struct MediaPlaylist { end_list_tag: Option, segments: Vec, } + impl MediaPlaylist { /// Returns the `EXT-X-VERSION` tag contained in the playlist. - pub fn version_tag(&self) -> ExtXVersion { + pub const fn version_tag(&self) -> ExtXVersion { self.version_tag } /// Returns the `EXT-X-TARGETDURATION` tag contained in the playlist. - pub fn target_duration_tag(&self) -> ExtXTargetDuration { + pub const fn target_duration_tag(&self) -> ExtXTargetDuration { self.target_duration_tag } /// Returns the `EXT-X-MEDIA-SEQUENCE` tag contained in the playlist. - pub fn media_sequence_tag(&self) -> Option { + pub const fn media_sequence_tag(&self) -> Option { self.media_sequence_tag } /// Returns the `EXT-X-DISCONTINUITY-SEQUENCE` tag contained in the playlist. - pub fn discontinuity_sequence_tag(&self) -> Option { + pub const fn discontinuity_sequence_tag(&self) -> Option { self.discontinuity_sequence_tag } /// Returns the `EXT-X-PLAYLIST-TYPE` tag contained in the playlist. - pub fn playlist_type_tag(&self) -> Option { + pub const fn playlist_type_tag(&self) -> Option { self.playlist_type_tag } /// Returns the `EXT-X-I-FRAMES-ONLY` tag contained in the playlist. - pub fn i_frames_only_tag(&self) -> Option { + pub const fn i_frames_only_tag(&self) -> Option { self.i_frames_only_tag } /// Returns the `EXT-X-INDEPENDENT-SEGMENTS` tag contained in the playlist. - pub fn independent_segments_tag(&self) -> Option { + pub const fn independent_segments_tag(&self) -> Option { self.independent_segments_tag } /// Returns the `EXT-X-START` tag contained in the playlist. - pub fn start_tag(&self) -> Option { + pub const fn start_tag(&self) -> Option { self.start_tag } /// Returns the `EXT-X-ENDLIST` tag contained in the playlist. - pub fn end_list_tag(&self) -> Option { + pub const fn end_list_tag(&self) -> Option { self.end_list_tag } @@ -251,6 +254,7 @@ impl MediaPlaylist { &self.segments } } + impl fmt::Display for MediaPlaylist { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { writeln!(f, "{}", ExtM3u)?; @@ -285,6 +289,7 @@ impl fmt::Display for MediaPlaylist { Ok(()) } } + impl FromStr for MediaPlaylist { type Err = Error; fn from_str(s: &str) -> Result { @@ -297,6 +302,7 @@ impl FromStr for MediaPlaylist { pub struct MediaPlaylistOptions { allowable_excess_duration: Duration, } + impl MediaPlaylistOptions { /// Makes a new `MediaPlaylistOptions` with the default settings. pub fn new() -> Self { @@ -450,6 +456,7 @@ impl MediaPlaylistOptions { track!(builder.finish()) } } + impl Default for MediaPlaylistOptions { fn default() -> Self { Self::new() diff --git a/src/media_segment.rs b/src/media_segment.rs index 7794819..602b51d 100644 --- a/src/media_segment.rs +++ b/src/media_segment.rs @@ -19,6 +19,7 @@ pub struct MediaSegmentBuilder { inf_tag: Option, uri: Option, } + impl MediaSegmentBuilder { /// Makes a new `MediaSegmentBuilder` instance. pub fn new() -> Self { @@ -70,6 +71,7 @@ impl MediaSegmentBuilder { }) } } + impl Default for MediaSegmentBuilder { fn default() -> Self { Self::new() @@ -88,6 +90,7 @@ pub struct MediaSegment { inf_tag: ExtInf, uri: SingleLineString, } + impl fmt::Display for MediaSegment { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { for t in &self.key_tags { @@ -113,19 +116,20 @@ impl fmt::Display for MediaSegment { Ok(()) } } + impl MediaSegment { /// Returns the URI of the media segment. - pub fn uri(&self) -> &SingleLineString { + pub const fn uri(&self) -> &SingleLineString { &self.uri } /// Returns the `EXT-X-INF` tag associated with the media segment. - pub fn inf_tag(&self) -> &ExtInf { + pub const fn inf_tag(&self) -> &ExtInf { &self.inf_tag } /// Returns the `EXT-X-BYTERANGE` tag associated with the media segment. - pub fn byte_range_tag(&self) -> Option { + pub const fn byte_range_tag(&self) -> Option { self.byte_range_tag } @@ -135,7 +139,7 @@ impl MediaSegment { } /// Returns the `EXT-X-DISCONTINUITY` tag associated with the media segment. - pub fn discontinuity_tag(&self) -> Option { + pub const fn discontinuity_tag(&self) -> Option { self.discontinuity_tag } diff --git a/src/tags/basic/m3u.rs b/src/tags/basic/m3u.rs index 5d44b90..9595a18 100644 --- a/src/tags/basic/m3u.rs +++ b/src/tags/basic/m3u.rs @@ -8,21 +8,25 @@ use std::str::FromStr; /// [4.3.1.1. EXTM3U]: https://tools.ietf.org/html/rfc8216#section-4.3.1.1 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct ExtM3u; + impl ExtM3u { pub(crate) const PREFIX: &'static str = "#EXTM3U"; /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(self) -> ProtocolVersion { + pub const fn requires_version(&self) -> ProtocolVersion { ProtocolVersion::V1 } } + impl fmt::Display for ExtM3u { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { Self::PREFIX.fmt(f) } } + impl FromStr for ExtM3u { type Err = Error; + fn from_str(s: &str) -> Result { track_assert_eq!(s, Self::PREFIX, ErrorKind::InvalidInput); Ok(ExtM3u) diff --git a/src/tags/basic/version.rs b/src/tags/basic/version.rs index f0ab35f..c321e21 100644 --- a/src/tags/basic/version.rs +++ b/src/tags/basic/version.rs @@ -15,17 +15,17 @@ impl ExtXVersion { pub(crate) const PREFIX: &'static str = "#EXT-X-VERSION:"; /// Makes a new `ExtXVersion` tag. - pub fn new(version: ProtocolVersion) -> Self { + pub const fn new(version: ProtocolVersion) -> Self { ExtXVersion { version } } /// Returns the protocol compatibility version of the playlist containing this tag. - pub fn version(self) -> ProtocolVersion { + pub const fn version(&self) -> ProtocolVersion { self.version } /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(self) -> ProtocolVersion { + pub const fn requires_version(&self) -> ProtocolVersion { ProtocolVersion::V1 } } diff --git a/src/tags/master_playlist/i_frame_stream_inf.rs b/src/tags/master_playlist/i_frame_stream_inf.rs index e287fcb..f10082f 100644 --- a/src/tags/master_playlist/i_frame_stream_inf.rs +++ b/src/tags/master_playlist/i_frame_stream_inf.rs @@ -37,17 +37,17 @@ impl ExtXIFrameStreamInf { } /// Returns the URI that identifies the associated media playlist. - pub fn uri(&self) -> &String { + pub const fn uri(&self) -> &String { &self.uri } /// Returns the peak segment bit rate of the variant stream. - pub fn bandwidth(&self) -> u64 { + pub const fn bandwidth(&self) -> u64 { self.bandwidth } /// Returns the average segment bit rate of the variant stream. - pub fn average_bandwidth(&self) -> Option { + pub const fn average_bandwidth(&self) -> Option { self.average_bandwidth } @@ -57,12 +57,12 @@ impl ExtXIFrameStreamInf { } /// Returns the optimal pixel resolution at which to display all the video in the variant stream. - pub fn resolution(&self) -> Option { + pub const fn resolution(&self) -> Option { self.resolution } /// Returns the HDCP level of the variant stream. - pub fn hdcp_level(&self) -> Option { + pub const fn hdcp_level(&self) -> Option { self.hdcp_level } @@ -72,7 +72,7 @@ impl ExtXIFrameStreamInf { } /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(&self) -> ProtocolVersion { + pub const fn requires_version(&self) -> ProtocolVersion { ProtocolVersion::V1 } } @@ -104,6 +104,7 @@ impl fmt::Display for ExtXIFrameStreamInf { impl FromStr for ExtXIFrameStreamInf { type Err = Error; + fn from_str(s: &str) -> Result { track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); diff --git a/src/tags/master_playlist/media.rs b/src/tags/master_playlist/media.rs index 24d2c22..7c17b3b 100644 --- a/src/tags/master_playlist/media.rs +++ b/src/tags/master_playlist/media.rs @@ -24,7 +24,7 @@ pub struct ExtXMediaBuilder { impl ExtXMediaBuilder { /// Makes a `ExtXMediaBuilder` instance. - pub fn new() -> Self { + pub const fn new() -> Self { ExtXMediaBuilder { media_type: None, uri: None, @@ -194,17 +194,17 @@ impl ExtXMedia { } /// Returns the type of the media associated with this tag. - pub fn media_type(&self) -> MediaType { + pub const fn media_type(&self) -> MediaType { self.media_type } /// Returns the identifier that specifies the group to which the rendition belongs. - pub fn group_id(&self) -> &String { + pub const fn group_id(&self) -> &String { &self.group_id } /// Returns a human-readable description of the rendition. - pub fn name(&self) -> &String { + pub const fn name(&self) -> &String { &self.name } @@ -224,23 +224,23 @@ impl ExtXMedia { } /// Returns whether this is the default rendition. - pub fn default(&self) -> bool { + pub const fn default(&self) -> bool { self.default } /// Returns whether the client may choose to /// play this rendition in the absence of explicit user preference. - pub fn autoselect(&self) -> bool { + pub const fn autoselect(&self) -> bool { self.autoselect } /// Returns whether the rendition contains content that is considered essential to play. - pub fn forced(&self) -> bool { + pub const fn forced(&self) -> bool { self.forced } /// Returns the identifier that specifies a rendition within the segments in the media playlist. - pub fn instream_id(&self) -> Option { + pub const fn instream_id(&self) -> Option { self.instream_id } @@ -308,6 +308,7 @@ impl fmt::Display for ExtXMedia { impl FromStr for ExtXMedia { type Err = Error; + fn from_str(s: &str) -> Result { track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); diff --git a/src/tags/master_playlist/session_data.rs b/src/tags/master_playlist/session_data.rs index 75da90c..32b1633 100644 --- a/src/tags/master_playlist/session_data.rs +++ b/src/tags/master_playlist/session_data.rs @@ -37,12 +37,12 @@ impl ExtXSessionData { } /// Returns the identifier of the data. - pub fn data_id(&self) -> &String { + pub const fn data_id(&self) -> &String { &self.data_id } /// Returns the session data. - pub fn data(&self) -> &SessionData { + pub const fn data(&self) -> &SessionData { &self.data } @@ -52,7 +52,7 @@ impl ExtXSessionData { } /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(&self) -> ProtocolVersion { + pub const fn requires_version(&self) -> ProtocolVersion { ProtocolVersion::V1 } } @@ -74,6 +74,7 @@ impl fmt::Display for ExtXSessionData { impl FromStr for ExtXSessionData { type Err = Error; + fn from_str(s: &str) -> Result { track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); diff --git a/src/tags/master_playlist/session_key.rs b/src/tags/master_playlist/session_key.rs index aafae51..26cea97 100644 --- a/src/tags/master_playlist/session_key.rs +++ b/src/tags/master_playlist/session_key.rs @@ -15,12 +15,12 @@ impl ExtXSessionKey { pub(crate) const PREFIX: &'static str = "#EXT-X-SESSION-KEY:"; /// Makes a new `ExtXSessionKey` tag. - pub fn new(key: DecryptionKey) -> Self { + pub const fn new(key: DecryptionKey) -> Self { ExtXSessionKey { key } } /// Returns a decryption key for the playlist. - pub fn key(&self) -> &DecryptionKey { + pub const fn key(&self) -> &DecryptionKey { &self.key } diff --git a/src/tags/master_playlist/stream_inf.rs b/src/tags/master_playlist/stream_inf.rs index 28e5bcd..81c8c28 100644 --- a/src/tags/master_playlist/stream_inf.rs +++ b/src/tags/master_playlist/stream_inf.rs @@ -30,7 +30,7 @@ impl ExtXStreamInf { pub(crate) const PREFIX: &'static str = "#EXT-X-STREAM-INF:"; /// Makes a new `ExtXStreamInf` tag. - pub fn new(uri: SingleLineString, bandwidth: u64) -> Self { + pub const fn new(uri: SingleLineString, bandwidth: u64) -> Self { ExtXStreamInf { uri, bandwidth, @@ -47,17 +47,17 @@ impl ExtXStreamInf { } /// Returns the URI that identifies the associated media playlist. - pub fn uri(&self) -> &SingleLineString { + pub const fn uri(&self) -> &SingleLineString { &self.uri } /// Returns the peak segment bit rate of the variant stream. - pub fn bandwidth(&self) -> u64 { + pub const fn bandwidth(&self) -> u64 { self.bandwidth } /// Returns the average segment bit rate of the variant stream. - pub fn average_bandwidth(&self) -> Option { + pub const fn average_bandwidth(&self) -> Option { self.average_bandwidth } @@ -67,17 +67,17 @@ impl ExtXStreamInf { } /// Returns the optimal pixel resolution at which to display all the video in the variant stream. - pub fn resolution(&self) -> Option { + pub const fn resolution(&self) -> Option { self.resolution } /// Returns the maximum frame rate for all the video in the variant stream. - pub fn frame_rate(&self) -> Option { + pub const fn frame_rate(&self) -> Option { self.frame_rate } /// Returns the HDCP level of the variant stream. - pub fn hdcp_level(&self) -> Option { + pub const fn hdcp_level(&self) -> Option { self.hdcp_level } @@ -102,7 +102,7 @@ impl ExtXStreamInf { } /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(&self) -> ProtocolVersion { + pub const fn requires_version(&self) -> ProtocolVersion { ProtocolVersion::V1 } } @@ -145,6 +145,7 @@ impl fmt::Display for ExtXStreamInf { impl FromStr for ExtXStreamInf { type Err = Error; + fn from_str(s: &str) -> Result { let mut lines = s.splitn(2, '\n'); let first_line = lines.next().expect("Never fails").trim_end_matches('\r'); diff --git a/src/tags/media_playlist/discontinuity_sequence.rs b/src/tags/media_playlist/discontinuity_sequence.rs index 9aa6539..07b245b 100644 --- a/src/tags/media_playlist/discontinuity_sequence.rs +++ b/src/tags/media_playlist/discontinuity_sequence.rs @@ -16,18 +16,18 @@ impl ExtXDiscontinuitySequence { pub(crate) const PREFIX: &'static str = "#EXT-X-DISCONTINUITY-SEQUENCE:"; /// Makes a new `ExtXDiscontinuitySequence` tag. - pub fn new(seq_num: u64) -> Self { + pub const fn new(seq_num: u64) -> Self { ExtXDiscontinuitySequence { seq_num } } /// Returns the discontinuity sequence number of /// the first media segment that appears in the associated playlist. - pub fn seq_num(self) -> u64 { + pub const fn seq_num(self) -> u64 { self.seq_num } /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(self) -> ProtocolVersion { + pub const fn requires_version(self) -> ProtocolVersion { ProtocolVersion::V1 } } @@ -40,6 +40,7 @@ impl fmt::Display for ExtXDiscontinuitySequence { impl FromStr for ExtXDiscontinuitySequence { type Err = Error; + fn from_str(s: &str) -> Result { track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); let seq_num = may_invalid!(s.split_at(Self::PREFIX.len()).1.parse())?; diff --git a/src/tags/media_playlist/end_list.rs b/src/tags/media_playlist/end_list.rs index f8e333f..ddeb5c0 100644 --- a/src/tags/media_playlist/end_list.rs +++ b/src/tags/media_playlist/end_list.rs @@ -12,17 +12,20 @@ impl ExtXEndList { pub(crate) const PREFIX: &'static str = "#EXT-X-ENDLIST"; /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(self) -> ProtocolVersion { + pub const fn requires_version(self) -> ProtocolVersion { ProtocolVersion::V1 } } + impl fmt::Display for ExtXEndList { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { Self::PREFIX.fmt(f) } } + impl FromStr for ExtXEndList { type Err = Error; + fn from_str(s: &str) -> Result { track_assert_eq!(s, Self::PREFIX, ErrorKind::InvalidInput); Ok(ExtXEndList) diff --git a/src/tags/media_playlist/i_frames_only.rs b/src/tags/media_playlist/i_frames_only.rs index 4bea636..90db7f4 100644 --- a/src/tags/media_playlist/i_frames_only.rs +++ b/src/tags/media_playlist/i_frames_only.rs @@ -13,7 +13,7 @@ impl ExtXIFramesOnly { pub(crate) const PREFIX: &'static str = "#EXT-X-I-FRAMES-ONLY"; /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(self) -> ProtocolVersion { + pub const fn requires_version(self) -> ProtocolVersion { ProtocolVersion::V4 } } @@ -26,6 +26,7 @@ impl fmt::Display for ExtXIFramesOnly { impl FromStr for ExtXIFramesOnly { type Err = Error; + fn from_str(s: &str) -> Result { track_assert_eq!(s, Self::PREFIX, ErrorKind::InvalidInput); Ok(ExtXIFramesOnly) diff --git a/src/tags/media_playlist/media_sequence.rs b/src/tags/media_playlist/media_sequence.rs index 99be333..47f75bf 100644 --- a/src/tags/media_playlist/media_sequence.rs +++ b/src/tags/media_playlist/media_sequence.rs @@ -16,17 +16,17 @@ impl ExtXMediaSequence { pub(crate) const PREFIX: &'static str = "#EXT-X-MEDIA-SEQUENCE:"; /// Makes a new `ExtXMediaSequence` tag. - pub fn new(seq_num: u64) -> Self { + pub const fn new(seq_num: u64) -> Self { ExtXMediaSequence { seq_num } } /// Returns the sequence number of the first media segment that appears in the associated playlist. - pub fn seq_num(self) -> u64 { + pub const fn seq_num(self) -> u64 { self.seq_num } /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(self) -> ProtocolVersion { + pub const fn requires_version(self) -> ProtocolVersion { ProtocolVersion::V1 } } @@ -39,6 +39,7 @@ impl fmt::Display for ExtXMediaSequence { impl FromStr for ExtXMediaSequence { type Err = Error; + fn from_str(s: &str) -> Result { track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); let seq_num = may_invalid!(s.split_at(Self::PREFIX.len()).1.parse())?; diff --git a/src/tags/media_playlist/playlist_type.rs b/src/tags/media_playlist/playlist_type.rs index e2a5f99..16d9672 100644 --- a/src/tags/media_playlist/playlist_type.rs +++ b/src/tags/media_playlist/playlist_type.rs @@ -16,17 +16,17 @@ impl ExtXPlaylistType { pub(crate) const PREFIX: &'static str = "#EXT-X-PLAYLIST-TYPE:"; /// Makes a new `ExtXPlaylistType` tag. - pub fn new(playlist_type: PlaylistType) -> Self { + pub const fn new(playlist_type: PlaylistType) -> Self { ExtXPlaylistType { playlist_type } } /// Returns the type of the associated media playlist. - pub fn playlist_type(self) -> PlaylistType { + pub const fn playlist_type(self) -> PlaylistType { self.playlist_type } /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(self) -> ProtocolVersion { + pub const fn requires_version(self) -> ProtocolVersion { ProtocolVersion::V1 } } @@ -39,6 +39,7 @@ impl fmt::Display for ExtXPlaylistType { impl FromStr for ExtXPlaylistType { type Err = Error; + fn from_str(s: &str) -> Result { track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); let playlist_type = may_invalid!(s.split_at(Self::PREFIX.len()).1.parse())?; diff --git a/src/tags/media_playlist/target_duration.rs b/src/tags/media_playlist/target_duration.rs index a2af667..2f759b9 100644 --- a/src/tags/media_playlist/target_duration.rs +++ b/src/tags/media_playlist/target_duration.rs @@ -19,18 +19,18 @@ impl ExtXTargetDuration { /// Makes a new `ExtXTargetduration` tag. /// /// Note that the nanoseconds part of the `duration` will be discarded. - pub fn new(duration: Duration) -> Self { + pub const fn new(duration: Duration) -> Self { let duration = Duration::from_secs(duration.as_secs()); ExtXTargetDuration { duration } } /// Returns the maximum media segment duration in the associated playlist. - pub fn duration(&self) -> Duration { + pub const fn duration(&self) -> Duration { self.duration } /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(&self) -> ProtocolVersion { + pub const fn requires_version(&self) -> ProtocolVersion { ProtocolVersion::V1 } } diff --git a/src/tags/media_segment/byte_range.rs b/src/tags/media_segment/byte_range.rs index 52397ba..bbc5ab1 100644 --- a/src/tags/media_segment/byte_range.rs +++ b/src/tags/media_segment/byte_range.rs @@ -16,17 +16,17 @@ impl ExtXByteRange { pub(crate) const PREFIX: &'static str = "#EXT-X-BYTERANGE:"; /// Makes a new `ExtXByteRange` tag. - pub fn new(range: ByteRange) -> Self { + pub const fn new(range: ByteRange) -> Self { ExtXByteRange { range } } /// Returns the range of the associated media segment. - pub fn range(&self) -> ByteRange { + pub const fn range(&self) -> ByteRange { self.range } /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(&self) -> ProtocolVersion { + pub const fn requires_version(&self) -> ProtocolVersion { ProtocolVersion::V4 } } @@ -39,6 +39,7 @@ impl fmt::Display for ExtXByteRange { impl FromStr for ExtXByteRange { type Err = Error; + fn from_str(s: &str) -> Result { track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); let range = may_invalid!(s.split_at(Self::PREFIX.len()).1.parse())?; diff --git a/src/tags/media_segment/date_range.rs b/src/tags/media_segment/date_range.rs index 788bd8c..dae13ce 100644 --- a/src/tags/media_segment/date_range.rs +++ b/src/tags/media_segment/date_range.rs @@ -32,7 +32,7 @@ impl ExtXDateRange { pub(crate) const PREFIX: &'static str = "#EXT-X-DATERANGE:"; /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(&self) -> ProtocolVersion { + pub const fn requires_version(&self) -> ProtocolVersion { ProtocolVersion::V1 } } diff --git a/src/tags/media_segment/discontinuity.rs b/src/tags/media_segment/discontinuity.rs index 8e23325..d0f3563 100644 --- a/src/tags/media_segment/discontinuity.rs +++ b/src/tags/media_segment/discontinuity.rs @@ -12,15 +12,17 @@ impl ExtXDiscontinuity { pub(crate) const PREFIX: &'static str = "#EXT-X-DISCONTINUITY"; /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(self) -> ProtocolVersion { + pub const fn requires_version(self) -> ProtocolVersion { ProtocolVersion::V1 } } + impl fmt::Display for ExtXDiscontinuity { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { Self::PREFIX.fmt(f) } } + impl FromStr for ExtXDiscontinuity { type Err = Error; fn from_str(s: &str) -> Result { diff --git a/src/tags/media_segment/inf.rs b/src/tags/media_segment/inf.rs index 3543f69..ac215af 100644 --- a/src/tags/media_segment/inf.rs +++ b/src/tags/media_segment/inf.rs @@ -18,7 +18,7 @@ impl ExtInf { pub(crate) const PREFIX: &'static str = "#EXTINF:"; /// Makes a new `ExtInf` tag. - pub fn new(duration: Duration) -> Self { + pub const fn new(duration: Duration) -> Self { ExtInf { duration, title: None, @@ -26,7 +26,7 @@ impl ExtInf { } /// Makes a new `ExtInf` tag with the given title. - pub fn with_title(duration: Duration, title: SingleLineString) -> Self { + pub const fn with_title(duration: Duration, title: SingleLineString) -> Self { ExtInf { duration, title: Some(title), @@ -34,7 +34,7 @@ impl ExtInf { } /// Returns the duration of the associated media segment. - pub fn duration(&self) -> Duration { + pub const fn duration(&self) -> Duration { self.duration } diff --git a/src/tags/media_segment/key.rs b/src/tags/media_segment/key.rs index 9f2811f..e9dda27 100644 --- a/src/tags/media_segment/key.rs +++ b/src/tags/media_segment/key.rs @@ -16,14 +16,14 @@ impl ExtXKey { pub(crate) const PREFIX: &'static str = "#EXT-X-KEY:"; /// Makes a new `ExtXKey` tag. - pub fn new(key: DecryptionKey) -> Self { + pub const fn new(key: DecryptionKey) -> Self { ExtXKey { key: Some(key) } } /// Makes a new `ExtXKey` tag without a decryption key. /// /// This tag has the `METHDO=NONE` attribute. - pub fn new_without_key() -> Self { + pub const fn new_without_key() -> Self { ExtXKey { key: None } } @@ -54,6 +54,7 @@ impl fmt::Display for ExtXKey { impl FromStr for ExtXKey { type Err = Error; + fn from_str(s: &str) -> Result { track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); let suffix = s.split_at(Self::PREFIX.len()).1; diff --git a/src/tags/media_segment/map.rs b/src/tags/media_segment/map.rs index 96c45f8..c5c9933 100644 --- a/src/tags/media_segment/map.rs +++ b/src/tags/media_segment/map.rs @@ -34,17 +34,17 @@ impl ExtXMap { } /// Returns the URI that identifies a resource that contains the media initialization section. - pub fn uri(&self) -> &String { + pub const fn uri(&self) -> &String { &self.uri } /// Returns the range of the media initialization section. - pub fn range(&self) -> Option { + pub const fn range(&self) -> Option { self.range } /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(&self) -> ProtocolVersion { + pub const fn requires_version(&self) -> ProtocolVersion { ProtocolVersion::V6 } } @@ -62,6 +62,7 @@ impl fmt::Display for ExtXMap { impl FromStr for ExtXMap { type Err = Error; + fn from_str(s: &str) -> Result { track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); diff --git a/src/tags/media_segment/program_date_time.rs b/src/tags/media_segment/program_date_time.rs index b694c93..625fdeb 100644 --- a/src/tags/media_segment/program_date_time.rs +++ b/src/tags/media_segment/program_date_time.rs @@ -15,17 +15,17 @@ impl ExtXProgramDateTime { pub(crate) const PREFIX: &'static str = "#EXT-X-PROGRAM-DATE-TIME:"; /// Makes a new `ExtXProgramDateTime` tag. - pub fn new(date_time: SingleLineString) -> Self { + pub const fn new(date_time: SingleLineString) -> Self { ExtXProgramDateTime { date_time } } /// Returns the date-time of the first sample of the associated media segment. - pub fn date_time(&self) -> &SingleLineString { + pub const fn date_time(&self) -> &SingleLineString { &self.date_time } /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(&self) -> ProtocolVersion { + pub const fn requires_version(&self) -> ProtocolVersion { ProtocolVersion::V1 } } @@ -38,6 +38,7 @@ impl fmt::Display for ExtXProgramDateTime { impl FromStr for ExtXProgramDateTime { type Err = Error; + fn from_str(s: &str) -> Result { track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); let suffix = s.split_at(Self::PREFIX.len()).1; diff --git a/src/tags/shared/independent_segments.rs b/src/tags/shared/independent_segments.rs index d4916f9..2aa3e82 100644 --- a/src/tags/shared/independent_segments.rs +++ b/src/tags/shared/independent_segments.rs @@ -12,7 +12,7 @@ impl ExtXIndependentSegments { pub(crate) const PREFIX: &'static str = "#EXT-X-INDEPENDENT-SEGMENTS"; /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(self) -> ProtocolVersion { + pub const fn requires_version(&self) -> ProtocolVersion { ProtocolVersion::V1 } } @@ -25,6 +25,7 @@ impl fmt::Display for ExtXIndependentSegments { impl FromStr for ExtXIndependentSegments { type Err = Error; + fn from_str(s: &str) -> Result { track_assert_eq!(s, Self::PREFIX, ErrorKind::InvalidInput); Ok(ExtXIndependentSegments) diff --git a/src/tags/shared/start.rs b/src/tags/shared/start.rs index 5c301c1..560b144 100644 --- a/src/tags/shared/start.rs +++ b/src/tags/shared/start.rs @@ -18,7 +18,7 @@ impl ExtXStart { pub(crate) const PREFIX: &'static str = "#EXT-X-START:"; /// Makes a new `ExtXStart` tag. - pub fn new(time_offset: SignedDecimalFloatingPoint) -> Self { + pub const fn new(time_offset: SignedDecimalFloatingPoint) -> Self { ExtXStart { time_offset, precise: false, @@ -26,7 +26,7 @@ impl ExtXStart { } /// Makes a new `ExtXStart` tag with the given `precise` flag. - pub fn with_precise(time_offset: SignedDecimalFloatingPoint, precise: bool) -> Self { + pub const fn with_precise(time_offset: SignedDecimalFloatingPoint, precise: bool) -> Self { ExtXStart { time_offset, precise, @@ -34,18 +34,18 @@ impl ExtXStart { } /// Returns the time offset of the media segments in the playlist. - pub fn time_offset(&self) -> SignedDecimalFloatingPoint { + pub const fn time_offset(&self) -> SignedDecimalFloatingPoint { self.time_offset } /// Returns whether clients should not render media stream whose presentation times are /// prior to the specified time offset. - pub fn precise(&self) -> bool { + pub const fn precise(&self) -> bool { self.precise } /// Returns the protocol compatibility version that this tag requires. - pub fn requires_version(&self) -> ProtocolVersion { + pub const fn requires_version(&self) -> ProtocolVersion { ProtocolVersion::V1 } } @@ -63,6 +63,7 @@ impl fmt::Display for ExtXStart { impl FromStr for ExtXStart { type Err = Error; + fn from_str(s: &str) -> Result { track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); diff --git a/src/types/decimal_floating_point.rs b/src/types/decimal_floating_point.rs index 5cd33cc..aa555e9 100644 --- a/src/types/decimal_floating_point.rs +++ b/src/types/decimal_floating_point.rs @@ -26,7 +26,7 @@ impl DecimalFloatingPoint { } /// Converts `DecimalFloatingPoint` to `f64`. - pub fn as_f64(self) -> f64 { + pub const fn as_f64(self) -> f64 { self.0 } diff --git a/src/types/signed_decimal_floating_point.rs b/src/types/signed_decimal_floating_point.rs index 3c50998..999d0a2 100644 --- a/src/types/signed_decimal_floating_point.rs +++ b/src/types/signed_decimal_floating_point.rs @@ -24,7 +24,7 @@ impl SignedDecimalFloatingPoint { } /// Converts `DecimalFloatingPoint` to `f64`. - pub fn as_f64(self) -> f64 { + pub const fn as_f64(self) -> f64 { self.0 } }