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/protocol_version.rs
2019-09-06 13:20:40 +02:00

48 lines
1.3 KiB
Rust

use crate::{Error, ErrorKind, Result};
use std::fmt;
use std::str::{self, FromStr};
/// [7. Protocol Version Compatibility]
///
/// [7. Protocol Version Compatibility]: https://tools.ietf.org/html/rfc8216#section-7
#[allow(missing_docs)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum ProtocolVersion {
V1,
V2,
V3,
V4,
V5,
V6,
V7,
}
impl fmt::Display for ProtocolVersion {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let n = match *self {
ProtocolVersion::V1 => 1,
ProtocolVersion::V2 => 2,
ProtocolVersion::V3 => 3,
ProtocolVersion::V4 => 4,
ProtocolVersion::V5 => 5,
ProtocolVersion::V6 => 6,
ProtocolVersion::V7 => 7,
};
write!(f, "{}", n)
}
}
impl FromStr for ProtocolVersion {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
Ok(match s {
"1" => ProtocolVersion::V1,
"2" => ProtocolVersion::V2,
"3" => ProtocolVersion::V3,
"4" => ProtocolVersion::V4,
"5" => ProtocolVersion::V5,
"6" => ProtocolVersion::V6,
"7" => ProtocolVersion::V7,
_ => track_panic!(ErrorKind::InvalidInput, "Unknown protocol version: {:?}", s),
})
}
}