2019-09-06 10:55:00 +00:00
|
|
|
use std::fmt;
|
|
|
|
use std::str::FromStr;
|
2019-09-13 14:06:52 +00:00
|
|
|
|
|
|
|
use crate::types::{PlaylistType, ProtocolVersion};
|
|
|
|
use crate::utils::tag;
|
|
|
|
use crate::Error;
|
2019-09-06 10:55:00 +00:00
|
|
|
|
|
|
|
/// [4.3.3.5. EXT-X-PLAYLIST-TYPE]
|
|
|
|
///
|
|
|
|
/// [4.3.3.5. EXT-X-PLAYLIST-TYPE]: https://tools.ietf.org/html/rfc8216#section-4.3.3.5
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
|
|
pub struct ExtXPlaylistType {
|
|
|
|
playlist_type: PlaylistType,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ExtXPlaylistType {
|
|
|
|
pub(crate) const PREFIX: &'static str = "#EXT-X-PLAYLIST-TYPE:";
|
|
|
|
|
|
|
|
/// Makes a new `ExtXPlaylistType` tag.
|
2019-09-08 10:23:33 +00:00
|
|
|
pub const fn new(playlist_type: PlaylistType) -> Self {
|
2019-09-06 10:55:00 +00:00
|
|
|
ExtXPlaylistType { playlist_type }
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the type of the associated media playlist.
|
2019-09-08 10:23:33 +00:00
|
|
|
pub const fn playlist_type(self) -> PlaylistType {
|
2019-09-06 10:55:00 +00:00
|
|
|
self.playlist_type
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the protocol compatibility version that this tag requires.
|
2019-09-08 10:23:33 +00:00
|
|
|
pub const fn requires_version(self) -> ProtocolVersion {
|
2019-09-06 10:55:00 +00:00
|
|
|
ProtocolVersion::V1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for ExtXPlaylistType {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "{}{}", Self::PREFIX, self.playlist_type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for ExtXPlaylistType {
|
|
|
|
type Err = Error;
|
2019-09-08 10:23:33 +00:00
|
|
|
|
2019-09-13 14:06:52 +00:00
|
|
|
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
|
|
|
let input = tag(input, Self::PREFIX)?.parse()?;
|
|
|
|
|
|
|
|
Ok(ExtXPlaylistType::new(input))
|
2019-09-06 10:55:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ext_x_playlist_type() {
|
|
|
|
let tag = ExtXPlaylistType::new(PlaylistType::Vod);
|
|
|
|
let text = "#EXT-X-PLAYLIST-TYPE:VOD";
|
|
|
|
assert_eq!(text.parse().ok(), Some(tag));
|
|
|
|
assert_eq!(tag.to_string(), text);
|
|
|
|
assert_eq!(tag.requires_version(), ProtocolVersion::V1);
|
|
|
|
}
|
|
|
|
}
|