1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-06-02 07:50:30 +00:00
hls_m3u8/src/tags/media_segment/discontinuity.rs

67 lines
1.7 KiB
Rust
Raw Normal View History

use std::convert::TryFrom;
2019-09-06 10:55:00 +00:00
use std::fmt;
2019-10-04 09:02:21 +00:00
use crate::types::ProtocolVersion;
use crate::{Error, RequiredVersion};
2019-09-10 09:05:20 +00:00
2020-03-25 10:32:48 +00:00
/// The `ExtXDiscontinuity` tag indicates a discontinuity between the
/// `MediaSegment` that follows it and the one that preceded it.
2019-10-12 09:38:28 +00:00
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
2020-03-25 10:32:48 +00:00
pub(crate) struct ExtXDiscontinuity;
2019-09-10 09:05:20 +00:00
2019-09-06 10:55:00 +00:00
impl ExtXDiscontinuity {
pub(crate) const PREFIX: &'static str = "#EXT-X-DISCONTINUITY";
2019-09-22 08:57:28 +00:00
}
2019-09-06 10:55:00 +00:00
2020-02-02 12:38:11 +00:00
/// This tag requires [`ProtocolVersion::V1`].
2019-09-22 08:57:28 +00:00
impl RequiredVersion for ExtXDiscontinuity {
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 ExtXDiscontinuity {
2020-04-09 06:43:13 +00:00
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { Self::PREFIX.fmt(f) }
2019-09-06 10:55:00 +00:00
}
2019-09-08 10:23:33 +00:00
impl TryFrom<&str> for ExtXDiscontinuity {
type Error = Error;
2019-09-10 09:05:20 +00:00
fn try_from(input: &str) -> Result<Self, Self::Error> {
2020-08-11 08:36:44 +00:00
// the parser assumes that only a single line is passed as input,
// which should be "#EXT-X-DISCONTINUITY"
if input == Self::PREFIX {
Ok(Self)
} else {
Err(Error::unexpected_data(input))
}
2019-09-06 10:55:00 +00:00
}
}
#[cfg(test)]
mod test {
use super::*;
use pretty_assertions::assert_eq;
2019-09-06 10:55:00 +00:00
#[test]
2019-09-22 08:57:28 +00:00
fn test_display() {
assert_eq!(
ExtXDiscontinuity.to_string(),
"#EXT-X-DISCONTINUITY".to_string(),
)
}
#[test]
fn test_parser() {
assert_eq!(
ExtXDiscontinuity,
ExtXDiscontinuity::try_from("#EXT-X-DISCONTINUITY").unwrap()
2020-08-11 08:36:44 +00:00
);
assert!(ExtXDiscontinuity::try_from("#EXT-X-DISCONTINUITY:0").is_err());
}
2019-09-22 08:57:28 +00:00
#[test]
fn test_required_version() {
assert_eq!(ExtXDiscontinuity.required_version(), ProtocolVersion::V1)
2019-09-06 10:55:00 +00:00
}
}