2019-09-06 11:21:05 +00:00
|
|
|
use crate::types::QuotedString;
|
2019-09-06 11:20:40 +00:00
|
|
|
use crate::{Error, Result};
|
|
|
|
use std::fmt;
|
|
|
|
use std::str::{self, FromStr};
|
|
|
|
|
|
|
|
/// The identifier of a closed captions group or its absence.
|
|
|
|
///
|
|
|
|
/// 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, PartialEq, Eq, Hash)]
|
|
|
|
pub enum ClosedCaptions {
|
|
|
|
GroupId(QuotedString),
|
|
|
|
None,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for ClosedCaptions {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
|
|
|
ClosedCaptions::GroupId(ref x) => x.fmt(f),
|
|
|
|
ClosedCaptions::None => "NONE".fmt(f),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for ClosedCaptions {
|
|
|
|
type Err = Error;
|
|
|
|
fn from_str(s: &str) -> Result<Self> {
|
|
|
|
if s == "NONE" {
|
|
|
|
Ok(ClosedCaptions::None)
|
|
|
|
} else {
|
|
|
|
Ok(ClosedCaptions::GroupId(track!(s.parse())?))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|