use std::fmt;
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
enum Kind {
Dev,
Nightly,
Beta,
Stable,
}
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub struct Channel(Kind);
impl Channel {
pub fn read() -> Option<Channel> {
::get_version_and_date()
.and_then(|(version, _)| version)
.and_then(|version| Channel::parse(&version))
}
pub fn parse(version: &str) -> Option<Channel> {
if version.contains("-dev") {
Some(Channel(Kind::Dev))
} else if version.contains("-nightly") {
Some(Channel(Kind::Nightly))
} else if version.contains("-beta") {
Some(Channel(Kind::Beta))
} else if !version.contains("-") {
Some(Channel(Kind::Stable))
} else {
None
}
}
fn as_str(&self) -> &'static str {
match self.0 {
Kind::Dev => "dev",
Kind::Beta => "beta",
Kind::Nightly => "nightly",
Kind::Stable => "stable",
}
}
pub fn supports_features(&self) -> bool {
match self.0 {
Kind::Dev | Kind::Nightly => true,
Kind::Beta | Kind::Stable => false
}
}
pub fn is_dev(&self) -> bool {
match self.0 {
Kind::Dev => true,
_ => false
}
}
pub fn is_nightly(&self) -> bool {
match self.0 {
Kind::Nightly => true,
_ => false
}
}
pub fn is_beta(&self) -> bool {
match self.0 {
Kind::Beta => true,
_ => false
}
}
pub fn is_stable(&self) -> bool {
match self.0 {
Kind::Stable => true,
_ => false
}
}
}
impl fmt::Display for Channel {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.as_str())
}
}