use std::str::FromStr;
use std::sync::Arc;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Category {
Any,
Capable,
Efficient,
Judge,
Named(Arc<str>),
}
impl Category {
pub fn as_str(&self) -> &str {
match self {
Self::Any => "any",
Self::Capable => "capable",
Self::Efficient => "efficient",
Self::Judge => "judge",
Self::Named(name) => name,
}
}
}
impl FromStr for Category {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let c = match s {
"capable" => Self::Capable,
"efficient" => Self::Efficient,
"judge" => Self::Judge,
"any" => Self::Any,
"" => return Err("Category name cannot be empty".to_string()),
name => Self::Named(Arc::from(name)),
};
Ok(c)
}
}