From 5b44262dc826158167c77f33cffd31117a65e5f5 Mon Sep 17 00:00:00 2001 From: Luro02 <24826124+Luro02@users.noreply.github.com> Date: Sat, 5 Oct 2019 09:44:23 +0200 Subject: [PATCH] minor changes --- src/master_playlist.rs | 62 ++++++++++--------- src/media_playlist.rs | 6 +- src/tags/basic/m3u.rs | 21 ++++--- src/tags/basic/version.rs | 5 +- .../master_playlist/i_frame_stream_inf.rs | 5 +- src/tags/master_playlist/stream_inf.rs | 1 + 6 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/master_playlist.rs b/src/master_playlist.rs index 865b797..39713b1 100644 --- a/src/master_playlist.rs +++ b/src/master_playlist.rs @@ -28,54 +28,59 @@ pub struct MasterPlaylist { /// The default is the maximum version among the tags in the playlist. version_tag: ExtXVersion, #[builder(default)] - /// Sets the [ExtXIndependentSegments] tag. + /// Sets the [`ExtXIndependentSegments`] tag. independent_segments_tag: Option, #[builder(default)] - /// Sets the [ExtXStart] tag. + /// Sets the [`ExtXStart`] tag. start_tag: Option, - /// Sets the [ExtXMedia] tag. + #[builder(default)] + /// Sets the [`ExtXMedia`] tag. media_tags: Vec, - /// Sets all [ExtXStreamInf]s. + #[builder(default)] + /// Sets all [`ExtXStreamInf`]s. stream_inf_tags: Vec, - /// Sets all [ExtXIFrameStreamInf]s. + #[builder(default)] + /// Sets all [`ExtXIFrameStreamInf`]s. i_frame_stream_inf_tags: Vec, - /// Sets all [ExtXSessionData]s. + #[builder(default)] + /// Sets all [`ExtXSessionData`]s. session_data_tags: Vec, - /// Sets all [ExtXSessionKey]s. + #[builder(default)] + /// Sets all [`ExtXSessionKey`]s. session_key_tags: Vec, } impl MasterPlaylist { - /// Returns a Builder for a MasterPlaylist. + /// Returns a Builder for a [`MasterPlaylist`]. pub fn builder() -> MasterPlaylistBuilder { MasterPlaylistBuilder::default() } - /// Returns the `EXT-X-VERSION` tag contained in the playlist. - pub const fn version_tag(&self) -> ExtXVersion { self.version_tag } + /// Returns the [`ExtXVersion`] tag contained in the playlist. + pub const fn version(&self) -> ExtXVersion { self.version_tag } - /// Returns the `EXT-X-INDEPENDENT-SEGMENTS` tag contained in the playlist. + /// Returns the [`ExtXIndependentSegments`] tag contained in the playlist. pub const fn independent_segments_tag(&self) -> Option { self.independent_segments_tag } - /// Returns the `EXT-X-START` tag contained in the playlist. + /// Returns the [`ExtXStart`] tag contained in the playlist. pub const fn start_tag(&self) -> Option { self.start_tag } - /// Returns the `EXT-X-MEDIA` tags contained in the playlist. - pub fn media_tags(&self) -> &[ExtXMedia] { &self.media_tags } + /// Returns the [`ExtXMedia`] tags contained in the playlist. + pub const fn media_tags(&self) -> &Vec { &self.media_tags } - /// Returns the `EXT-X-STREAM-INF` tags contained in the playlist. - pub fn stream_inf_tags(&self) -> &[ExtXStreamInf] { &self.stream_inf_tags } + /// Returns the [`ExtXStreamInf`] tags contained in the playlist. + pub const fn stream_inf_tags(&self) -> &Vec { &self.stream_inf_tags } - /// Returns the `EXT-X-I-FRAME-STREAM-INF` tags contained in the playlist. - pub fn i_frame_stream_inf_tags(&self) -> &[ExtXIFrameStreamInf] { + /// Returns the [`ExtXIFrameStreamInf`] tags contained in the playlist. + pub const fn i_frame_stream_inf_tags(&self) -> &Vec { &self.i_frame_stream_inf_tags } - /// Returns the `EXT-X-SESSION-DATA` tags contained in the playlist. - pub fn session_data_tags(&self) -> &[ExtXSessionData] { &self.session_data_tags } + /// Returns the [`ExtXSessionData`] tags contained in the playlist. + pub const fn session_data_tags(&self) -> &Vec { &self.session_data_tags } - /// Returns the `EXT-X-SESSION-KEY` tags contained in the playlist. - pub fn session_key_tags(&self) -> &[ExtXSessionKey] { &self.session_key_tags } + /// Returns the [`ExtXSessionKey`] tags contained in the playlist. + pub const fn session_key_tags(&self) -> &Vec { &self.session_key_tags } } impl RequiredVersion for MasterPlaylist { @@ -85,10 +90,7 @@ impl RequiredVersion for MasterPlaylist { impl MasterPlaylistBuilder { fn validate(&self) -> Result<(), String> { let required_version = self.required_version(); - let specified_version = self - .version_tag - .unwrap_or_else(|| required_version.into()) - .version(); + let specified_version = self.version_tag.map_or(required_version, |p| p.version()); if required_version > specified_version { return Err(Error::required_version(required_version, specified_version).to_string()); @@ -107,15 +109,15 @@ impl MasterPlaylistBuilder { iter::empty() .chain( self.independent_segments_tag + .flatten() .iter() - .map(|t| t.iter().map(|t| t.required_version())) - .flatten(), + .map(|p| p.required_version()), ) .chain( self.start_tag + .flatten() .iter() - .map(|t| t.iter().map(|t| t.required_version())) - .flatten(), + .map(|p| p.required_version()), ) .chain( self.media_tags diff --git a/src/media_playlist.rs b/src/media_playlist.rs index 6630420..dba09db 100644 --- a/src/media_playlist.rs +++ b/src/media_playlist.rs @@ -72,11 +72,7 @@ impl MediaPlaylistBuilder { let specified_version = self.version_tag.map_or(required_version, |p| p.version()); if required_version > specified_version { - return Err(Error::custom(format!( - "required_version: {}, specified_version: {}", - required_version, specified_version - )) - .to_string()); + return Err(Error::required_version(required_version, specified_version).to_string()); } if let Some(target_duration) = &self.target_duration_tag { diff --git a/src/tags/basic/m3u.rs b/src/tags/basic/m3u.rs index 07077d3..e4620fe 100644 --- a/src/tags/basic/m3u.rs +++ b/src/tags/basic/m3u.rs @@ -5,7 +5,7 @@ use crate::types::ProtocolVersion; use crate::utils::tag; use crate::{Error, RequiredVersion}; -/// # [4.4.1.1. EXTM3U] +/// # [4.3.1.1. EXTM3U] /// The [`ExtM3u`] tag indicates that the file is an **Ext**ended **[`M3U`]** /// Playlist file. /// It is the at the start of every [`Media Playlist`] and [`Master Playlist`]. @@ -32,8 +32,7 @@ use crate::{Error, RequiredVersion}; /// [`Media Playlist`]: crate::MediaPlaylist /// [`Master Playlist`]: crate::MasterPlaylist /// [`M3U`]: https://en.wikipedia.org/wiki/M3U -/// [4.4.1.1. EXTM3U]: -/// https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-05#section-4.4.1.1 +/// [4.3.1.1. EXTM3U]: https://tools.ietf.org/html/rfc8216#section-4.3.1.1 #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)] pub struct ExtM3u; @@ -42,6 +41,15 @@ impl ExtM3u { } /// This tag requires [`ProtocolVersion::V1`]. +/// +/// # Example +/// ``` +/// # use hls_m3u8::tags::ExtM3u; +/// use hls_m3u8::types::ProtocolVersion; +/// use hls_m3u8::RequiredVersion; +/// +/// assert_eq!(ExtM3u.required_version(), ProtocolVersion::V1); +/// ``` impl RequiredVersion for ExtM3u { fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 } } @@ -70,11 +78,6 @@ mod test { #[test] fn test_parser() { - assert_eq!("#EXTM3U".parse::().ok(), Some(ExtM3u)); - } - - #[test] - fn test_required_version() { - assert_eq!(ExtM3u.required_version(), ProtocolVersion::V1); + assert_eq!("#EXTM3U".parse::().unwrap(), ExtM3u); } } diff --git a/src/tags/basic/version.rs b/src/tags/basic/version.rs index 54e559f..58bf1e1 100644 --- a/src/tags/basic/version.rs +++ b/src/tags/basic/version.rs @@ -5,7 +5,7 @@ use crate::types::ProtocolVersion; use crate::utils::tag; use crate::{Error, RequiredVersion}; -/// # [4.4.1.2. EXT-X-VERSION] +/// # [4.3.1.2. EXT-X-VERSION] /// The [`ExtXVersion`] tag indicates the compatibility version of the /// [`Master Playlist`] or [`Media Playlist`] file. /// It applies to the entire Playlist. @@ -41,8 +41,7 @@ use crate::{Error, RequiredVersion}; /// /// [`Media Playlist`]: crate::MediaPlaylist /// [`Master Playlist`]: crate::MasterPlaylist -/// [4.4.1.2. EXT-X-VERSION]: -/// https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-05#section-4.4.1.2 +/// [4.4.1.2. EXT-X-VERSION]: https://tools.ietf.org/html/rfc8216#section-4.3.1.2 #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] pub struct ExtXVersion(ProtocolVersion); diff --git a/src/tags/master_playlist/i_frame_stream_inf.rs b/src/tags/master_playlist/i_frame_stream_inf.rs index 7b051c6..e795c7f 100644 --- a/src/tags/master_playlist/i_frame_stream_inf.rs +++ b/src/tags/master_playlist/i_frame_stream_inf.rs @@ -7,7 +7,7 @@ use crate::types::{ProtocolVersion, StreamInf}; use crate::utils::{quote, tag, unquote}; use crate::{Error, RequiredVersion}; -/// # [4.4.5.3. EXT-X-I-FRAME-STREAM-INF] +/// # [4.3.5.3. EXT-X-I-FRAME-STREAM-INF] /// The [`ExtXIFrameStreamInf`] tag identifies a [`Media Playlist`] file, /// containing the I-frames of a multimedia presentation. /// @@ -16,8 +16,7 @@ use crate::{Error, RequiredVersion}; /// /// [`Master Playlist`]: crate::MasterPlaylist /// [`Media Playlist`]: crate::MediaPlaylist -/// [4.4.5.3. EXT-X-I-FRAME-STREAM-INF]: -/// https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-05#section-4.4.5.3 +/// [4.3.5.3. EXT-X-I-FRAME-STREAM-INF]: https://tools.ietf.org/html/rfc8216#section-4.3.4.5 #[derive(PartialOrd, Debug, Clone, PartialEq, Eq, Hash)] pub struct ExtXIFrameStreamInf { uri: String, diff --git a/src/tags/master_playlist/stream_inf.rs b/src/tags/master_playlist/stream_inf.rs index 065ed01..9c5127c 100644 --- a/src/tags/master_playlist/stream_inf.rs +++ b/src/tags/master_playlist/stream_inf.rs @@ -188,6 +188,7 @@ impl ExtXStreamInf { } } +/// This tag requires [`ProtocolVersion::V1`]. impl RequiredVersion for ExtXStreamInf { fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 } }