use std::fmt;
use super::uap_json::structures::Edition;
use super::uap::providers::Provider;
#[derive(Debug, Clone)]
pub struct CustomCategoryError {
message: String
}
impl fmt::Display for CustomCategoryError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.message)
}
}
#[derive(Debug, PartialEq, Eq, Hash, Clone, Ord, PartialOrd)]
pub enum CategoryIndex {
_034,
_048,
}
impl CategoryIndex {
pub fn as_str(&self) -> &'static str {
match self {
CategoryIndex::_034 => "034",
CategoryIndex::_048 => "048",
}
}
pub fn as_string(&self) -> String {
self.as_str().to_string()
}
pub fn as_u8(&self) -> u8 {
match self {
CategoryIndex::_034 => 34,
CategoryIndex::_048 => 48,
}
}
pub fn from_u8(category: u8) -> Option<CategoryIndex> {
if category == 34 {
return Some(CategoryIndex::_034);
} else {
if category == 48 {
return Some(CategoryIndex::_048);
}
}
None
}
pub fn from_str(category_str: &str) -> Option<&Self> {
match category_str {
"034" => Some(&CategoryIndex::_034),
"048" => Some(&CategoryIndex::_048),
_ => None
}
}
}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Category {
pub key: CategoryKey,
pub description: String
}
impl Category {
pub fn new(key: CategoryKey, description: &str) -> Category {
Category {
key,
description: description.to_string(),
}
}
}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct CategoryKey {
pub index: CategoryIndex,
pub edition: Edition,
pub provider: Provider
}