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

fixed clippy warnings

This commit is contained in:
Luro02 2019-09-08 12:23:33 +02:00
parent 1966a7608d
commit cf97a45f60
30 changed files with 127 additions and 87 deletions

View file

@ -9,6 +9,7 @@ readme = "README.md"
license = "MIT" license = "MIT"
keywords = ["hls", "m3u8"] keywords = ["hls", "m3u8"]
edition = "2018" edition = "2018"
categories = ["parser"]
[badges] [badges]
travis-ci = {repository = "sile/hls_m3u8"} travis-ci = {repository = "sile/hls_m3u8"}

View file

@ -1,3 +1,8 @@
#![warn(
//clippy::pedantic,
clippy::nursery,
clippy::cargo
)]
//! [HLS] m3u8 parser/generator. //! [HLS] m3u8 parser/generator.
//! //!
//! [HLS]: https://tools.ietf.org/html/rfc8216 //! [HLS]: https://tools.ietf.org/html/rfc8216

View file

@ -9,7 +9,7 @@ pub struct Lines<'a> {
input: &'a str, input: &'a str,
} }
impl<'a> Lines<'a> { impl<'a> Lines<'a> {
pub fn new(input: &'a str) -> Self { pub const fn new(input: &'a str) -> Self {
Lines { input } Lines { input }
} }

View file

@ -238,17 +238,17 @@ pub struct MasterPlaylist {
impl MasterPlaylist { impl MasterPlaylist {
/// Returns the `EXT-X-VERSION` tag contained in the playlist. /// 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 self.version_tag
} }
/// Returns the `EXT-X-INDEPENDENT-SEGMENTS` tag contained in the playlist. /// Returns the `EXT-X-INDEPENDENT-SEGMENTS` tag contained in the playlist.
pub fn independent_segments_tag(&self) -> Option<ExtXIndependentSegments> { pub const fn independent_segments_tag(&self) -> Option<ExtXIndependentSegments> {
self.independent_segments_tag self.independent_segments_tag
} }
/// Returns the `EXT-X-START` tag contained in the playlist. /// Returns the `EXT-X-START` tag contained in the playlist.
pub fn start_tag(&self) -> Option<ExtXStart> { pub const fn start_tag(&self) -> Option<ExtXStart> {
self.start_tag self.start_tag
} }

View file

@ -27,6 +27,7 @@ pub struct MediaPlaylistBuilder {
segments: Vec<MediaSegment>, segments: Vec<MediaSegment>,
options: MediaPlaylistOptions, options: MediaPlaylistOptions,
} }
impl MediaPlaylistBuilder { impl MediaPlaylistBuilder {
/// Makes a new `MediaPlaylistBuilder` instance. /// Makes a new `MediaPlaylistBuilder` instance.
pub fn new() -> Self { pub fn new() -> Self {
@ -180,6 +181,7 @@ impl MediaPlaylistBuilder {
.unwrap_or(ProtocolVersion::V1) .unwrap_or(ProtocolVersion::V1)
} }
} }
impl Default for MediaPlaylistBuilder { impl Default for MediaPlaylistBuilder {
fn default() -> Self { fn default() -> Self {
Self::new() Self::new()
@ -200,49 +202,50 @@ pub struct MediaPlaylist {
end_list_tag: Option<ExtXEndList>, end_list_tag: Option<ExtXEndList>,
segments: Vec<MediaSegment>, segments: Vec<MediaSegment>,
} }
impl MediaPlaylist { impl MediaPlaylist {
/// Returns the `EXT-X-VERSION` tag contained in the playlist. /// 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 self.version_tag
} }
/// Returns the `EXT-X-TARGETDURATION` tag contained in the playlist. /// 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 self.target_duration_tag
} }
/// Returns the `EXT-X-MEDIA-SEQUENCE` tag contained in the playlist. /// Returns the `EXT-X-MEDIA-SEQUENCE` tag contained in the playlist.
pub fn media_sequence_tag(&self) -> Option<ExtXMediaSequence> { pub const fn media_sequence_tag(&self) -> Option<ExtXMediaSequence> {
self.media_sequence_tag self.media_sequence_tag
} }
/// Returns the `EXT-X-DISCONTINUITY-SEQUENCE` tag contained in the playlist. /// Returns the `EXT-X-DISCONTINUITY-SEQUENCE` tag contained in the playlist.
pub fn discontinuity_sequence_tag(&self) -> Option<ExtXDiscontinuitySequence> { pub const fn discontinuity_sequence_tag(&self) -> Option<ExtXDiscontinuitySequence> {
self.discontinuity_sequence_tag self.discontinuity_sequence_tag
} }
/// Returns the `EXT-X-PLAYLIST-TYPE` tag contained in the playlist. /// Returns the `EXT-X-PLAYLIST-TYPE` tag contained in the playlist.
pub fn playlist_type_tag(&self) -> Option<ExtXPlaylistType> { pub const fn playlist_type_tag(&self) -> Option<ExtXPlaylistType> {
self.playlist_type_tag self.playlist_type_tag
} }
/// Returns the `EXT-X-I-FRAMES-ONLY` tag contained in the playlist. /// Returns the `EXT-X-I-FRAMES-ONLY` tag contained in the playlist.
pub fn i_frames_only_tag(&self) -> Option<ExtXIFramesOnly> { pub const fn i_frames_only_tag(&self) -> Option<ExtXIFramesOnly> {
self.i_frames_only_tag self.i_frames_only_tag
} }
/// Returns the `EXT-X-INDEPENDENT-SEGMENTS` tag contained in the playlist. /// Returns the `EXT-X-INDEPENDENT-SEGMENTS` tag contained in the playlist.
pub fn independent_segments_tag(&self) -> Option<ExtXIndependentSegments> { pub const fn independent_segments_tag(&self) -> Option<ExtXIndependentSegments> {
self.independent_segments_tag self.independent_segments_tag
} }
/// Returns the `EXT-X-START` tag contained in the playlist. /// Returns the `EXT-X-START` tag contained in the playlist.
pub fn start_tag(&self) -> Option<ExtXStart> { pub const fn start_tag(&self) -> Option<ExtXStart> {
self.start_tag self.start_tag
} }
/// Returns the `EXT-X-ENDLIST` tag contained in the playlist. /// Returns the `EXT-X-ENDLIST` tag contained in the playlist.
pub fn end_list_tag(&self) -> Option<ExtXEndList> { pub const fn end_list_tag(&self) -> Option<ExtXEndList> {
self.end_list_tag self.end_list_tag
} }
@ -251,6 +254,7 @@ impl MediaPlaylist {
&self.segments &self.segments
} }
} }
impl fmt::Display for MediaPlaylist { impl fmt::Display for MediaPlaylist {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "{}", ExtM3u)?; writeln!(f, "{}", ExtM3u)?;
@ -285,6 +289,7 @@ impl fmt::Display for MediaPlaylist {
Ok(()) Ok(())
} }
} }
impl FromStr for MediaPlaylist { impl FromStr for MediaPlaylist {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
@ -297,6 +302,7 @@ impl FromStr for MediaPlaylist {
pub struct MediaPlaylistOptions { pub struct MediaPlaylistOptions {
allowable_excess_duration: Duration, allowable_excess_duration: Duration,
} }
impl MediaPlaylistOptions { impl MediaPlaylistOptions {
/// Makes a new `MediaPlaylistOptions` with the default settings. /// Makes a new `MediaPlaylistOptions` with the default settings.
pub fn new() -> Self { pub fn new() -> Self {
@ -450,6 +456,7 @@ impl MediaPlaylistOptions {
track!(builder.finish()) track!(builder.finish())
} }
} }
impl Default for MediaPlaylistOptions { impl Default for MediaPlaylistOptions {
fn default() -> Self { fn default() -> Self {
Self::new() Self::new()

View file

@ -19,6 +19,7 @@ pub struct MediaSegmentBuilder {
inf_tag: Option<ExtInf>, inf_tag: Option<ExtInf>,
uri: Option<SingleLineString>, uri: Option<SingleLineString>,
} }
impl MediaSegmentBuilder { impl MediaSegmentBuilder {
/// Makes a new `MediaSegmentBuilder` instance. /// Makes a new `MediaSegmentBuilder` instance.
pub fn new() -> Self { pub fn new() -> Self {
@ -70,6 +71,7 @@ impl MediaSegmentBuilder {
}) })
} }
} }
impl Default for MediaSegmentBuilder { impl Default for MediaSegmentBuilder {
fn default() -> Self { fn default() -> Self {
Self::new() Self::new()
@ -88,6 +90,7 @@ pub struct MediaSegment {
inf_tag: ExtInf, inf_tag: ExtInf,
uri: SingleLineString, uri: SingleLineString,
} }
impl fmt::Display for MediaSegment { impl fmt::Display for MediaSegment {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for t in &self.key_tags { for t in &self.key_tags {
@ -113,19 +116,20 @@ impl fmt::Display for MediaSegment {
Ok(()) Ok(())
} }
} }
impl MediaSegment { impl MediaSegment {
/// Returns the URI of the media segment. /// Returns the URI of the media segment.
pub fn uri(&self) -> &SingleLineString { pub const fn uri(&self) -> &SingleLineString {
&self.uri &self.uri
} }
/// Returns the `EXT-X-INF` tag associated with the media segment. /// 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 &self.inf_tag
} }
/// Returns the `EXT-X-BYTERANGE` tag associated with the media segment. /// Returns the `EXT-X-BYTERANGE` tag associated with the media segment.
pub fn byte_range_tag(&self) -> Option<ExtXByteRange> { pub const fn byte_range_tag(&self) -> Option<ExtXByteRange> {
self.byte_range_tag self.byte_range_tag
} }
@ -135,7 +139,7 @@ impl MediaSegment {
} }
/// Returns the `EXT-X-DISCONTINUITY` tag associated with the media segment. /// Returns the `EXT-X-DISCONTINUITY` tag associated with the media segment.
pub fn discontinuity_tag(&self) -> Option<ExtXDiscontinuity> { pub const fn discontinuity_tag(&self) -> Option<ExtXDiscontinuity> {
self.discontinuity_tag self.discontinuity_tag
} }

View file

@ -8,21 +8,25 @@ use std::str::FromStr;
/// [4.3.1.1. EXTM3U]: https://tools.ietf.org/html/rfc8216#section-4.3.1.1 /// [4.3.1.1. EXTM3U]: https://tools.ietf.org/html/rfc8216#section-4.3.1.1
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ExtM3u; pub struct ExtM3u;
impl ExtM3u { impl ExtM3u {
pub(crate) const PREFIX: &'static str = "#EXTM3U"; pub(crate) const PREFIX: &'static str = "#EXTM3U";
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(self) -> ProtocolVersion { pub const fn requires_version(&self) -> ProtocolVersion {
ProtocolVersion::V1 ProtocolVersion::V1
} }
} }
impl fmt::Display for ExtM3u { impl fmt::Display for ExtM3u {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Self::PREFIX.fmt(f) Self::PREFIX.fmt(f)
} }
} }
impl FromStr for ExtM3u { impl FromStr for ExtM3u {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
track_assert_eq!(s, Self::PREFIX, ErrorKind::InvalidInput); track_assert_eq!(s, Self::PREFIX, ErrorKind::InvalidInput);
Ok(ExtM3u) Ok(ExtM3u)

View file

@ -15,17 +15,17 @@ impl ExtXVersion {
pub(crate) const PREFIX: &'static str = "#EXT-X-VERSION:"; pub(crate) const PREFIX: &'static str = "#EXT-X-VERSION:";
/// Makes a new `ExtXVersion` tag. /// Makes a new `ExtXVersion` tag.
pub fn new(version: ProtocolVersion) -> Self { pub const fn new(version: ProtocolVersion) -> Self {
ExtXVersion { version } ExtXVersion { version }
} }
/// Returns the protocol compatibility version of the playlist containing this tag. /// Returns the protocol compatibility version of the playlist containing this tag.
pub fn version(self) -> ProtocolVersion { pub const fn version(&self) -> ProtocolVersion {
self.version self.version
} }
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(self) -> ProtocolVersion { pub const fn requires_version(&self) -> ProtocolVersion {
ProtocolVersion::V1 ProtocolVersion::V1
} }
} }

View file

@ -37,17 +37,17 @@ impl ExtXIFrameStreamInf {
} }
/// Returns the URI that identifies the associated media playlist. /// Returns the URI that identifies the associated media playlist.
pub fn uri(&self) -> &String { pub const fn uri(&self) -> &String {
&self.uri &self.uri
} }
/// Returns the peak segment bit rate of the variant stream. /// Returns the peak segment bit rate of the variant stream.
pub fn bandwidth(&self) -> u64 { pub const fn bandwidth(&self) -> u64 {
self.bandwidth self.bandwidth
} }
/// Returns the average segment bit rate of the variant stream. /// Returns the average segment bit rate of the variant stream.
pub fn average_bandwidth(&self) -> Option<u64> { pub const fn average_bandwidth(&self) -> Option<u64> {
self.average_bandwidth 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. /// Returns the optimal pixel resolution at which to display all the video in the variant stream.
pub fn resolution(&self) -> Option<DecimalResolution> { pub const fn resolution(&self) -> Option<DecimalResolution> {
self.resolution self.resolution
} }
/// Returns the HDCP level of the variant stream. /// Returns the HDCP level of the variant stream.
pub fn hdcp_level(&self) -> Option<HdcpLevel> { pub const fn hdcp_level(&self) -> Option<HdcpLevel> {
self.hdcp_level self.hdcp_level
} }
@ -72,7 +72,7 @@ impl ExtXIFrameStreamInf {
} }
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(&self) -> ProtocolVersion { pub const fn requires_version(&self) -> ProtocolVersion {
ProtocolVersion::V1 ProtocolVersion::V1
} }
} }
@ -104,6 +104,7 @@ impl fmt::Display for ExtXIFrameStreamInf {
impl FromStr for ExtXIFrameStreamInf { impl FromStr for ExtXIFrameStreamInf {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput);

View file

@ -24,7 +24,7 @@ pub struct ExtXMediaBuilder {
impl ExtXMediaBuilder { impl ExtXMediaBuilder {
/// Makes a `ExtXMediaBuilder` instance. /// Makes a `ExtXMediaBuilder` instance.
pub fn new() -> Self { pub const fn new() -> Self {
ExtXMediaBuilder { ExtXMediaBuilder {
media_type: None, media_type: None,
uri: None, uri: None,
@ -194,17 +194,17 @@ impl ExtXMedia {
} }
/// Returns the type of the media associated with this tag. /// 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 self.media_type
} }
/// Returns the identifier that specifies the group to which the rendition belongs. /// 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 &self.group_id
} }
/// Returns a human-readable description of the rendition. /// Returns a human-readable description of the rendition.
pub fn name(&self) -> &String { pub const fn name(&self) -> &String {
&self.name &self.name
} }
@ -224,23 +224,23 @@ impl ExtXMedia {
} }
/// Returns whether this is the default rendition. /// Returns whether this is the default rendition.
pub fn default(&self) -> bool { pub const fn default(&self) -> bool {
self.default self.default
} }
/// Returns whether the client may choose to /// Returns whether the client may choose to
/// play this rendition in the absence of explicit user preference. /// play this rendition in the absence of explicit user preference.
pub fn autoselect(&self) -> bool { pub const fn autoselect(&self) -> bool {
self.autoselect self.autoselect
} }
/// Returns whether the rendition contains content that is considered essential to play. /// 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 self.forced
} }
/// Returns the identifier that specifies a rendition within the segments in the media playlist. /// Returns the identifier that specifies a rendition within the segments in the media playlist.
pub fn instream_id(&self) -> Option<InStreamId> { pub const fn instream_id(&self) -> Option<InStreamId> {
self.instream_id self.instream_id
} }
@ -308,6 +308,7 @@ impl fmt::Display for ExtXMedia {
impl FromStr for ExtXMedia { impl FromStr for ExtXMedia {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput);

View file

@ -37,12 +37,12 @@ impl ExtXSessionData {
} }
/// Returns the identifier of the data. /// Returns the identifier of the data.
pub fn data_id(&self) -> &String { pub const fn data_id(&self) -> &String {
&self.data_id &self.data_id
} }
/// Returns the session data. /// Returns the session data.
pub fn data(&self) -> &SessionData { pub const fn data(&self) -> &SessionData {
&self.data &self.data
} }
@ -52,7 +52,7 @@ impl ExtXSessionData {
} }
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(&self) -> ProtocolVersion { pub const fn requires_version(&self) -> ProtocolVersion {
ProtocolVersion::V1 ProtocolVersion::V1
} }
} }
@ -74,6 +74,7 @@ impl fmt::Display for ExtXSessionData {
impl FromStr for ExtXSessionData { impl FromStr for ExtXSessionData {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput);

View file

@ -15,12 +15,12 @@ impl ExtXSessionKey {
pub(crate) const PREFIX: &'static str = "#EXT-X-SESSION-KEY:"; pub(crate) const PREFIX: &'static str = "#EXT-X-SESSION-KEY:";
/// Makes a new `ExtXSessionKey` tag. /// Makes a new `ExtXSessionKey` tag.
pub fn new(key: DecryptionKey) -> Self { pub const fn new(key: DecryptionKey) -> Self {
ExtXSessionKey { key } ExtXSessionKey { key }
} }
/// Returns a decryption key for the playlist. /// Returns a decryption key for the playlist.
pub fn key(&self) -> &DecryptionKey { pub const fn key(&self) -> &DecryptionKey {
&self.key &self.key
} }

View file

@ -30,7 +30,7 @@ impl ExtXStreamInf {
pub(crate) const PREFIX: &'static str = "#EXT-X-STREAM-INF:"; pub(crate) const PREFIX: &'static str = "#EXT-X-STREAM-INF:";
/// Makes a new `ExtXStreamInf` tag. /// Makes a new `ExtXStreamInf` tag.
pub fn new(uri: SingleLineString, bandwidth: u64) -> Self { pub const fn new(uri: SingleLineString, bandwidth: u64) -> Self {
ExtXStreamInf { ExtXStreamInf {
uri, uri,
bandwidth, bandwidth,
@ -47,17 +47,17 @@ impl ExtXStreamInf {
} }
/// Returns the URI that identifies the associated media playlist. /// Returns the URI that identifies the associated media playlist.
pub fn uri(&self) -> &SingleLineString { pub const fn uri(&self) -> &SingleLineString {
&self.uri &self.uri
} }
/// Returns the peak segment bit rate of the variant stream. /// Returns the peak segment bit rate of the variant stream.
pub fn bandwidth(&self) -> u64 { pub const fn bandwidth(&self) -> u64 {
self.bandwidth self.bandwidth
} }
/// Returns the average segment bit rate of the variant stream. /// Returns the average segment bit rate of the variant stream.
pub fn average_bandwidth(&self) -> Option<u64> { pub const fn average_bandwidth(&self) -> Option<u64> {
self.average_bandwidth 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. /// Returns the optimal pixel resolution at which to display all the video in the variant stream.
pub fn resolution(&self) -> Option<DecimalResolution> { pub const fn resolution(&self) -> Option<DecimalResolution> {
self.resolution self.resolution
} }
/// Returns the maximum frame rate for all the video in the variant stream. /// Returns the maximum frame rate for all the video in the variant stream.
pub fn frame_rate(&self) -> Option<DecimalFloatingPoint> { pub const fn frame_rate(&self) -> Option<DecimalFloatingPoint> {
self.frame_rate self.frame_rate
} }
/// Returns the HDCP level of the variant stream. /// Returns the HDCP level of the variant stream.
pub fn hdcp_level(&self) -> Option<HdcpLevel> { pub const fn hdcp_level(&self) -> Option<HdcpLevel> {
self.hdcp_level self.hdcp_level
} }
@ -102,7 +102,7 @@ impl ExtXStreamInf {
} }
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(&self) -> ProtocolVersion { pub const fn requires_version(&self) -> ProtocolVersion {
ProtocolVersion::V1 ProtocolVersion::V1
} }
} }
@ -145,6 +145,7 @@ impl fmt::Display for ExtXStreamInf {
impl FromStr for ExtXStreamInf { impl FromStr for ExtXStreamInf {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
let mut lines = s.splitn(2, '\n'); let mut lines = s.splitn(2, '\n');
let first_line = lines.next().expect("Never fails").trim_end_matches('\r'); let first_line = lines.next().expect("Never fails").trim_end_matches('\r');

View file

@ -16,18 +16,18 @@ impl ExtXDiscontinuitySequence {
pub(crate) const PREFIX: &'static str = "#EXT-X-DISCONTINUITY-SEQUENCE:"; pub(crate) const PREFIX: &'static str = "#EXT-X-DISCONTINUITY-SEQUENCE:";
/// Makes a new `ExtXDiscontinuitySequence` tag. /// Makes a new `ExtXDiscontinuitySequence` tag.
pub fn new(seq_num: u64) -> Self { pub const fn new(seq_num: u64) -> Self {
ExtXDiscontinuitySequence { seq_num } ExtXDiscontinuitySequence { seq_num }
} }
/// Returns the discontinuity sequence number of /// Returns the discontinuity sequence number of
/// the first media segment that appears in the associated playlist. /// 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 self.seq_num
} }
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(self) -> ProtocolVersion { pub const fn requires_version(self) -> ProtocolVersion {
ProtocolVersion::V1 ProtocolVersion::V1
} }
} }
@ -40,6 +40,7 @@ impl fmt::Display for ExtXDiscontinuitySequence {
impl FromStr for ExtXDiscontinuitySequence { impl FromStr for ExtXDiscontinuitySequence {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput);
let seq_num = may_invalid!(s.split_at(Self::PREFIX.len()).1.parse())?; let seq_num = may_invalid!(s.split_at(Self::PREFIX.len()).1.parse())?;

View file

@ -12,17 +12,20 @@ impl ExtXEndList {
pub(crate) const PREFIX: &'static str = "#EXT-X-ENDLIST"; pub(crate) const PREFIX: &'static str = "#EXT-X-ENDLIST";
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(self) -> ProtocolVersion { pub const fn requires_version(self) -> ProtocolVersion {
ProtocolVersion::V1 ProtocolVersion::V1
} }
} }
impl fmt::Display for ExtXEndList { impl fmt::Display for ExtXEndList {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Self::PREFIX.fmt(f) Self::PREFIX.fmt(f)
} }
} }
impl FromStr for ExtXEndList { impl FromStr for ExtXEndList {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
track_assert_eq!(s, Self::PREFIX, ErrorKind::InvalidInput); track_assert_eq!(s, Self::PREFIX, ErrorKind::InvalidInput);
Ok(ExtXEndList) Ok(ExtXEndList)

View file

@ -13,7 +13,7 @@ impl ExtXIFramesOnly {
pub(crate) const PREFIX: &'static str = "#EXT-X-I-FRAMES-ONLY"; pub(crate) const PREFIX: &'static str = "#EXT-X-I-FRAMES-ONLY";
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(self) -> ProtocolVersion { pub const fn requires_version(self) -> ProtocolVersion {
ProtocolVersion::V4 ProtocolVersion::V4
} }
} }
@ -26,6 +26,7 @@ impl fmt::Display for ExtXIFramesOnly {
impl FromStr for ExtXIFramesOnly { impl FromStr for ExtXIFramesOnly {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
track_assert_eq!(s, Self::PREFIX, ErrorKind::InvalidInput); track_assert_eq!(s, Self::PREFIX, ErrorKind::InvalidInput);
Ok(ExtXIFramesOnly) Ok(ExtXIFramesOnly)

View file

@ -16,17 +16,17 @@ impl ExtXMediaSequence {
pub(crate) const PREFIX: &'static str = "#EXT-X-MEDIA-SEQUENCE:"; pub(crate) const PREFIX: &'static str = "#EXT-X-MEDIA-SEQUENCE:";
/// Makes a new `ExtXMediaSequence` tag. /// Makes a new `ExtXMediaSequence` tag.
pub fn new(seq_num: u64) -> Self { pub const fn new(seq_num: u64) -> Self {
ExtXMediaSequence { seq_num } ExtXMediaSequence { seq_num }
} }
/// Returns the sequence number of the first media segment that appears in the associated playlist. /// 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 self.seq_num
} }
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(self) -> ProtocolVersion { pub const fn requires_version(self) -> ProtocolVersion {
ProtocolVersion::V1 ProtocolVersion::V1
} }
} }
@ -39,6 +39,7 @@ impl fmt::Display for ExtXMediaSequence {
impl FromStr for ExtXMediaSequence { impl FromStr for ExtXMediaSequence {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput);
let seq_num = may_invalid!(s.split_at(Self::PREFIX.len()).1.parse())?; let seq_num = may_invalid!(s.split_at(Self::PREFIX.len()).1.parse())?;

View file

@ -16,17 +16,17 @@ impl ExtXPlaylistType {
pub(crate) const PREFIX: &'static str = "#EXT-X-PLAYLIST-TYPE:"; pub(crate) const PREFIX: &'static str = "#EXT-X-PLAYLIST-TYPE:";
/// Makes a new `ExtXPlaylistType` tag. /// Makes a new `ExtXPlaylistType` tag.
pub fn new(playlist_type: PlaylistType) -> Self { pub const fn new(playlist_type: PlaylistType) -> Self {
ExtXPlaylistType { playlist_type } ExtXPlaylistType { playlist_type }
} }
/// Returns the type of the associated media playlist. /// Returns the type of the associated media playlist.
pub fn playlist_type(self) -> PlaylistType { pub const fn playlist_type(self) -> PlaylistType {
self.playlist_type self.playlist_type
} }
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(self) -> ProtocolVersion { pub const fn requires_version(self) -> ProtocolVersion {
ProtocolVersion::V1 ProtocolVersion::V1
} }
} }
@ -39,6 +39,7 @@ impl fmt::Display for ExtXPlaylistType {
impl FromStr for ExtXPlaylistType { impl FromStr for ExtXPlaylistType {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput);
let playlist_type = may_invalid!(s.split_at(Self::PREFIX.len()).1.parse())?; let playlist_type = may_invalid!(s.split_at(Self::PREFIX.len()).1.parse())?;

View file

@ -19,18 +19,18 @@ impl ExtXTargetDuration {
/// Makes a new `ExtXTargetduration` tag. /// Makes a new `ExtXTargetduration` tag.
/// ///
/// Note that the nanoseconds part of the `duration` will be discarded. /// 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()); let duration = Duration::from_secs(duration.as_secs());
ExtXTargetDuration { duration } ExtXTargetDuration { duration }
} }
/// Returns the maximum media segment duration in the associated playlist. /// Returns the maximum media segment duration in the associated playlist.
pub fn duration(&self) -> Duration { pub const fn duration(&self) -> Duration {
self.duration self.duration
} }
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(&self) -> ProtocolVersion { pub const fn requires_version(&self) -> ProtocolVersion {
ProtocolVersion::V1 ProtocolVersion::V1
} }
} }

View file

@ -16,17 +16,17 @@ impl ExtXByteRange {
pub(crate) const PREFIX: &'static str = "#EXT-X-BYTERANGE:"; pub(crate) const PREFIX: &'static str = "#EXT-X-BYTERANGE:";
/// Makes a new `ExtXByteRange` tag. /// Makes a new `ExtXByteRange` tag.
pub fn new(range: ByteRange) -> Self { pub const fn new(range: ByteRange) -> Self {
ExtXByteRange { range } ExtXByteRange { range }
} }
/// Returns the range of the associated media segment. /// Returns the range of the associated media segment.
pub fn range(&self) -> ByteRange { pub const fn range(&self) -> ByteRange {
self.range self.range
} }
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(&self) -> ProtocolVersion { pub const fn requires_version(&self) -> ProtocolVersion {
ProtocolVersion::V4 ProtocolVersion::V4
} }
} }
@ -39,6 +39,7 @@ impl fmt::Display for ExtXByteRange {
impl FromStr for ExtXByteRange { impl FromStr for ExtXByteRange {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput);
let range = may_invalid!(s.split_at(Self::PREFIX.len()).1.parse())?; let range = may_invalid!(s.split_at(Self::PREFIX.len()).1.parse())?;

View file

@ -32,7 +32,7 @@ impl ExtXDateRange {
pub(crate) const PREFIX: &'static str = "#EXT-X-DATERANGE:"; pub(crate) const PREFIX: &'static str = "#EXT-X-DATERANGE:";
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(&self) -> ProtocolVersion { pub const fn requires_version(&self) -> ProtocolVersion {
ProtocolVersion::V1 ProtocolVersion::V1
} }
} }

View file

@ -12,15 +12,17 @@ impl ExtXDiscontinuity {
pub(crate) const PREFIX: &'static str = "#EXT-X-DISCONTINUITY"; pub(crate) const PREFIX: &'static str = "#EXT-X-DISCONTINUITY";
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(self) -> ProtocolVersion { pub const fn requires_version(self) -> ProtocolVersion {
ProtocolVersion::V1 ProtocolVersion::V1
} }
} }
impl fmt::Display for ExtXDiscontinuity { impl fmt::Display for ExtXDiscontinuity {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Self::PREFIX.fmt(f) Self::PREFIX.fmt(f)
} }
} }
impl FromStr for ExtXDiscontinuity { impl FromStr for ExtXDiscontinuity {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {

View file

@ -18,7 +18,7 @@ impl ExtInf {
pub(crate) const PREFIX: &'static str = "#EXTINF:"; pub(crate) const PREFIX: &'static str = "#EXTINF:";
/// Makes a new `ExtInf` tag. /// Makes a new `ExtInf` tag.
pub fn new(duration: Duration) -> Self { pub const fn new(duration: Duration) -> Self {
ExtInf { ExtInf {
duration, duration,
title: None, title: None,
@ -26,7 +26,7 @@ impl ExtInf {
} }
/// Makes a new `ExtInf` tag with the given title. /// 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 { ExtInf {
duration, duration,
title: Some(title), title: Some(title),
@ -34,7 +34,7 @@ impl ExtInf {
} }
/// Returns the duration of the associated media segment. /// Returns the duration of the associated media segment.
pub fn duration(&self) -> Duration { pub const fn duration(&self) -> Duration {
self.duration self.duration
} }

View file

@ -16,14 +16,14 @@ impl ExtXKey {
pub(crate) const PREFIX: &'static str = "#EXT-X-KEY:"; pub(crate) const PREFIX: &'static str = "#EXT-X-KEY:";
/// Makes a new `ExtXKey` tag. /// Makes a new `ExtXKey` tag.
pub fn new(key: DecryptionKey) -> Self { pub const fn new(key: DecryptionKey) -> Self {
ExtXKey { key: Some(key) } ExtXKey { key: Some(key) }
} }
/// Makes a new `ExtXKey` tag without a decryption key. /// Makes a new `ExtXKey` tag without a decryption key.
/// ///
/// This tag has the `METHDO=NONE` attribute. /// This tag has the `METHDO=NONE` attribute.
pub fn new_without_key() -> Self { pub const fn new_without_key() -> Self {
ExtXKey { key: None } ExtXKey { key: None }
} }
@ -54,6 +54,7 @@ impl fmt::Display for ExtXKey {
impl FromStr for ExtXKey { impl FromStr for ExtXKey {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput);
let suffix = s.split_at(Self::PREFIX.len()).1; let suffix = s.split_at(Self::PREFIX.len()).1;

View file

@ -34,17 +34,17 @@ impl ExtXMap {
} }
/// Returns the URI that identifies a resource that contains the media initialization section. /// 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 &self.uri
} }
/// Returns the range of the media initialization section. /// Returns the range of the media initialization section.
pub fn range(&self) -> Option<ByteRange> { pub const fn range(&self) -> Option<ByteRange> {
self.range self.range
} }
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(&self) -> ProtocolVersion { pub const fn requires_version(&self) -> ProtocolVersion {
ProtocolVersion::V6 ProtocolVersion::V6
} }
} }
@ -62,6 +62,7 @@ impl fmt::Display for ExtXMap {
impl FromStr for ExtXMap { impl FromStr for ExtXMap {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput);

View file

@ -15,17 +15,17 @@ impl ExtXProgramDateTime {
pub(crate) const PREFIX: &'static str = "#EXT-X-PROGRAM-DATE-TIME:"; pub(crate) const PREFIX: &'static str = "#EXT-X-PROGRAM-DATE-TIME:";
/// Makes a new `ExtXProgramDateTime` tag. /// Makes a new `ExtXProgramDateTime` tag.
pub fn new(date_time: SingleLineString) -> Self { pub const fn new(date_time: SingleLineString) -> Self {
ExtXProgramDateTime { date_time } ExtXProgramDateTime { date_time }
} }
/// Returns the date-time of the first sample of the associated media segment. /// 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 &self.date_time
} }
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(&self) -> ProtocolVersion { pub const fn requires_version(&self) -> ProtocolVersion {
ProtocolVersion::V1 ProtocolVersion::V1
} }
} }
@ -38,6 +38,7 @@ impl fmt::Display for ExtXProgramDateTime {
impl FromStr for ExtXProgramDateTime { impl FromStr for ExtXProgramDateTime {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput);
let suffix = s.split_at(Self::PREFIX.len()).1; let suffix = s.split_at(Self::PREFIX.len()).1;

View file

@ -12,7 +12,7 @@ impl ExtXIndependentSegments {
pub(crate) const PREFIX: &'static str = "#EXT-X-INDEPENDENT-SEGMENTS"; pub(crate) const PREFIX: &'static str = "#EXT-X-INDEPENDENT-SEGMENTS";
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(self) -> ProtocolVersion { pub const fn requires_version(&self) -> ProtocolVersion {
ProtocolVersion::V1 ProtocolVersion::V1
} }
} }
@ -25,6 +25,7 @@ impl fmt::Display for ExtXIndependentSegments {
impl FromStr for ExtXIndependentSegments { impl FromStr for ExtXIndependentSegments {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
track_assert_eq!(s, Self::PREFIX, ErrorKind::InvalidInput); track_assert_eq!(s, Self::PREFIX, ErrorKind::InvalidInput);
Ok(ExtXIndependentSegments) Ok(ExtXIndependentSegments)

View file

@ -18,7 +18,7 @@ impl ExtXStart {
pub(crate) const PREFIX: &'static str = "#EXT-X-START:"; pub(crate) const PREFIX: &'static str = "#EXT-X-START:";
/// Makes a new `ExtXStart` tag. /// Makes a new `ExtXStart` tag.
pub fn new(time_offset: SignedDecimalFloatingPoint) -> Self { pub const fn new(time_offset: SignedDecimalFloatingPoint) -> Self {
ExtXStart { ExtXStart {
time_offset, time_offset,
precise: false, precise: false,
@ -26,7 +26,7 @@ impl ExtXStart {
} }
/// Makes a new `ExtXStart` tag with the given `precise` flag. /// 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 { ExtXStart {
time_offset, time_offset,
precise, precise,
@ -34,18 +34,18 @@ impl ExtXStart {
} }
/// Returns the time offset of the media segments in the playlist. /// 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 self.time_offset
} }
/// Returns whether clients should not render media stream whose presentation times are /// Returns whether clients should not render media stream whose presentation times are
/// prior to the specified time offset. /// prior to the specified time offset.
pub fn precise(&self) -> bool { pub const fn precise(&self) -> bool {
self.precise self.precise
} }
/// Returns the protocol compatibility version that this tag requires. /// Returns the protocol compatibility version that this tag requires.
pub fn requires_version(&self) -> ProtocolVersion { pub const fn requires_version(&self) -> ProtocolVersion {
ProtocolVersion::V1 ProtocolVersion::V1
} }
} }
@ -63,6 +63,7 @@ impl fmt::Display for ExtXStart {
impl FromStr for ExtXStart { impl FromStr for ExtXStart {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput);

View file

@ -26,7 +26,7 @@ impl DecimalFloatingPoint {
} }
/// Converts `DecimalFloatingPoint` to `f64`. /// Converts `DecimalFloatingPoint` to `f64`.
pub fn as_f64(self) -> f64 { pub const fn as_f64(self) -> f64 {
self.0 self.0
} }

View file

@ -24,7 +24,7 @@ impl SignedDecimalFloatingPoint {
} }
/// Converts `DecimalFloatingPoint` to `f64`. /// Converts `DecimalFloatingPoint` to `f64`.
pub fn as_f64(self) -> f64 { pub const fn as_f64(self) -> f64 {
self.0 self.0
} }
} }