2019-09-06 10:55:00 +00:00
|
|
|
use std::fmt;
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
2019-10-04 09:02:21 +00:00
|
|
|
use crate::types::ProtocolVersion;
|
2019-09-10 09:05:20 +00:00
|
|
|
use crate::utils::tag;
|
2019-10-04 09:02:21 +00:00
|
|
|
use crate::{Error, RequiredVersion};
|
2019-09-10 09:05:20 +00:00
|
|
|
|
2019-10-03 14:23:27 +00:00
|
|
|
/// The [`ExtM3u`] tag indicates that the file is an **Ext**ended **[`M3U`]**
|
2019-09-22 16:00:38 +00:00
|
|
|
/// Playlist file.
|
2020-02-14 12:05:18 +00:00
|
|
|
/// It is the at the start of every [`MediaPlaylist`] and [`MasterPlaylist`].
|
2019-09-06 10:55:00 +00:00
|
|
|
///
|
2020-02-14 12:05:18 +00:00
|
|
|
/// [`MediaPlaylist`]: crate::MediaPlaylist
|
|
|
|
/// [`MasterPlaylist`]: crate::MasterPlaylist
|
2019-10-03 14:23:27 +00:00
|
|
|
/// [`M3U`]: https://en.wikipedia.org/wiki/M3U
|
2019-09-22 16:00:38 +00:00
|
|
|
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
|
2020-02-06 11:27:48 +00:00
|
|
|
pub(crate) struct ExtM3u;
|
2019-09-08 10:23:33 +00:00
|
|
|
|
2019-09-06 10:55:00 +00:00
|
|
|
impl ExtM3u {
|
|
|
|
pub(crate) const PREFIX: &'static str = "#EXTM3U";
|
2019-09-22 08:57:28 +00:00
|
|
|
}
|
2019-09-06 10:55:00 +00:00
|
|
|
|
2019-10-03 14:23:27 +00:00
|
|
|
/// This tag requires [`ProtocolVersion::V1`].
|
2019-09-22 08:57:28 +00:00
|
|
|
impl RequiredVersion for ExtM3u {
|
2019-10-03 15:01:15 +00:00
|
|
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
2019-09-06 10:55:00 +00:00
|
|
|
}
|
2019-09-08 10:23:33 +00:00
|
|
|
|
2019-09-06 10:55:00 +00:00
|
|
|
impl fmt::Display for ExtM3u {
|
2020-04-09 06:43:13 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", Self::PREFIX) }
|
2019-09-06 10:55:00 +00:00
|
|
|
}
|
2019-09-08 10:23:33 +00:00
|
|
|
|
2019-09-06 10:55:00 +00:00
|
|
|
impl FromStr for ExtM3u {
|
|
|
|
type Err = Error;
|
2019-09-08 10:23:33 +00:00
|
|
|
|
2019-09-10 09:05:20 +00:00
|
|
|
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
|
|
|
tag(input, Self::PREFIX)?;
|
2019-10-03 14:23:27 +00:00
|
|
|
Ok(Self)
|
2019-09-06 10:55:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
2019-10-08 13:42:33 +00:00
|
|
|
use pretty_assertions::assert_eq;
|
2019-09-06 10:55:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2019-09-08 10:49:22 +00:00
|
|
|
fn test_display() {
|
|
|
|
assert_eq!(ExtM3u.to_string(), "#EXTM3U".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_parser() {
|
2019-10-05 07:44:23 +00:00
|
|
|
assert_eq!("#EXTM3U".parse::<ExtM3u>().unwrap(), ExtM3u);
|
2020-02-06 11:28:54 +00:00
|
|
|
assert!("#EXTM2U".parse::<ExtM3u>().is_err());
|
2019-09-06 10:55:00 +00:00
|
|
|
}
|
2019-10-05 14:08:03 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_required_version() {
|
|
|
|
assert_eq!(ExtM3u.required_version(), ProtocolVersion::V1);
|
|
|
|
}
|
2019-09-06 10:55:00 +00:00
|
|
|
}
|