use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub enum Sector {
Battery,
Textile,
UnsoldGoods,
Steel,
Electronics,
Construction,
Tyre,
Toy,
Aluminium,
Furniture,
Detergent,
Other,
}
impl Sector {
pub const fn minimum_retention_years(&self) -> u32 {
match self {
Self::Battery => 10,
Self::Textile | Self::UnsoldGoods => 10,
Self::Steel => 10,
Self::Electronics => 10,
Self::Construction => 10,
Self::Tyre => 10,
Self::Toy => 10,
Self::Aluminium => 10,
Self::Furniture => 10,
Self::Detergent => 10,
Self::Other => 10,
}
}
pub const fn catalog_key(&self) -> &'static str {
match self {
Self::Battery => "battery",
Self::Textile => "textile",
Self::UnsoldGoods => "unsold-goods",
Self::Steel => "steel",
Self::Electronics => "electronics",
Self::Construction => "construction",
Self::Tyre => "tyre",
Self::Toy => "toy",
Self::Aluminium => "aluminium",
Self::Furniture => "furniture",
Self::Detergent => "detergent",
Self::Other => "other",
}
}
pub const fn wire_str(&self) -> &'static str {
match self {
Self::Battery => "battery",
Self::Textile => "textile",
Self::UnsoldGoods => "unsoldGoods",
Self::Steel => "steel",
Self::Electronics => "electronics",
Self::Construction => "construction",
Self::Tyre => "tyre",
Self::Toy => "toy",
Self::Aluminium => "aluminium",
Self::Furniture => "furniture",
Self::Detergent => "detergent",
Self::Other => "other",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn wire_str_matches_serde_serialization() {
for sector in [
Sector::Battery,
Sector::Textile,
Sector::UnsoldGoods,
Sector::Steel,
Sector::Electronics,
Sector::Construction,
Sector::Tyre,
Sector::Toy,
Sector::Aluminium,
Sector::Furniture,
Sector::Detergent,
Sector::Other,
] {
let serialized = serde_json::to_value(§or).unwrap();
assert_eq!(
serialized.as_str().unwrap(),
sector.wire_str(),
"wire_str() disagrees with serde for {sector:?}"
);
}
}
}