1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-05-18 08:22:59 +00:00
hls_m3u8/src/types/hdcp_level.rs
2019-09-06 13:46:21 +02:00

59 lines
1.4 KiB
Rust

use crate::{Error, ErrorKind, Result};
use std::fmt;
use std::str::{self, FromStr};
/// HDCP level.
///
/// See: [4.3.4.2. EXT-X-STREAM-INF]
///
/// [4.3.4.2. EXT-X-STREAM-INF]: https://tools.ietf.org/html/rfc8216#section-4.3.4.2
#[allow(missing_docs)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum HdcpLevel {
Type0,
None,
}
impl fmt::Display for HdcpLevel {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
HdcpLevel::Type0 => "TYPE-0".fmt(f),
HdcpLevel::None => "NONE".fmt(f),
}
}
}
impl FromStr for HdcpLevel {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
match s {
"TYPE-0" => Ok(HdcpLevel::Type0),
"NONE" => Ok(HdcpLevel::None),
_ => track_panic!(ErrorKind::InvalidInput, "Unknown HDCP level: {:?}", s),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_display() {
let level = HdcpLevel::Type0;
assert_eq!(level.to_string(), "TYPE-0".to_string());
let level = HdcpLevel::None;
assert_eq!(level.to_string(), "NONE".to_string());
}
#[test]
fn test_parse() {
let level = HdcpLevel::Type0;
assert_eq!(level, "TYPE-0".parse::<HdcpLevel>().unwrap());
let level = HdcpLevel::None;
assert_eq!(level, "NONE".parse::<HdcpLevel>().unwrap());
}
}