1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-06-13 18:49:25 +00:00
hls_m3u8/src/types/protocol_version.rs

63 lines
1.6 KiB
Rust
Raw Normal View History

2019-09-06 11:20:40 +00:00
use std::fmt;
2019-09-15 17:09:48 +00:00
use std::str::FromStr;
2019-09-06 11:20:40 +00:00
2019-09-13 14:06:52 +00:00
use crate::Error;
2019-09-06 11:20:40 +00:00
/// [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,
}
2019-09-17 13:40:10 +00:00
impl ProtocolVersion {
/// Returns the newest ProtocolVersion, that is supported by this library.
pub const fn latest() -> Self {
Self::V7
}
}
2019-09-06 11:20:40 +00:00
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,
}
2019-09-06 11:20:40 +00:00
};
write!(f, "{}", n)
}
}
2019-09-17 13:40:10 +00:00
2019-09-06 11:20:40 +00:00
impl FromStr for ProtocolVersion {
type Err = Error;
2019-09-13 14:06:52 +00:00
fn from_str(input: &str) -> Result<Self, Self::Err> {
Ok({
match input {
"1" => ProtocolVersion::V1,
"2" => ProtocolVersion::V2,
"3" => ProtocolVersion::V3,
"4" => ProtocolVersion::V4,
"5" => ProtocolVersion::V5,
"6" => ProtocolVersion::V6,
"7" => ProtocolVersion::V7,
_ => return Err(Error::unknown_protocol_version(input)),
}
2019-09-06 11:20:40 +00:00
})
}
}