use std::str::FromStr;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Logical(bool);
impl Logical {
pub const fn get(self) -> bool {
self.0
}
}
impl From<Logical> for bool {
fn from(value: Logical) -> Self {
value.0
}
}
impl From<bool> for Logical {
fn from(value: bool) -> Self {
Self(value)
}
}
impl std::fmt::Display for Logical {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(if self.0 { "yes" } else { "no" })
}
}
impl FromStr for Logical {
type Err = LogicalParseError;
fn from_str(value: &str) -> Result<Self, Self::Err> {
if value.eq_ignore_ascii_case("yes") || value.eq_ignore_ascii_case("true") {
Ok(Self(true))
} else if value.eq_ignore_ascii_case("no") || value.eq_ignore_ascii_case("false") {
Ok(Self(false))
} else {
Err(LogicalParseError)
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
#[error("expected yes, true, no, or false")]
pub struct LogicalParseError;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum OsType {
Unix,
Windows,
}
impl std::fmt::Display for OsType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::Unix => "unix",
Self::Windows => "windows",
})
}
}
impl FromStr for OsType {
type Err = OsTypeParseError;
fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
"unix" => Ok(Self::Unix),
"windows" => Ok(Self::Windows),
_ => Err(OsTypeParseError),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
#[error("expected unix or windows")]
pub struct OsTypeParseError;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Priority {
Base,
Recommended,
Optional,
Contrib,
}
impl std::fmt::Display for Priority {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::Base => "base",
Self::Recommended => "recommended",
Self::Optional => "optional",
Self::Contrib => "contrib",
})
}
}
impl FromStr for Priority {
type Err = PriorityParseError;
fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
"base" => Ok(Self::Base),
"recommended" => Ok(Self::Recommended),
"optional" => Ok(Self::Optional),
"contrib" => Ok(Self::Contrib),
_ => Err(PriorityParseError),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
#[error("expected base, recommended, optional, or contrib")]
pub struct PriorityParseError;