use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Methodology {
pub id: String,
pub version: u32,
}
impl Methodology {
pub fn new(id: impl Into<String>, version: u32) -> Self {
Self {
id: id.into(),
version,
}
}
pub fn rte_direct() -> Self {
Self::new("rte-direct", 1)
}
pub fn acv_ademe() -> Self {
Self::new("acv-ademe", 1)
}
pub fn acv_ademe_consumption() -> Self {
Self::new("acv-ademe", 2)
}
}
impl fmt::Display for Methodology {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}@v{}", self.id, self.version)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Vintage {
Tr,
Consolidated,
Definitive,
}
impl Vintage {
pub fn code(self) -> &'static str {
match self {
Vintage::Tr => "tr",
Vintage::Consolidated => "consolidated",
Vintage::Definitive => "definitive",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn vintage_quality_ordering() {
assert!(Vintage::Definitive > Vintage::Consolidated);
assert!(Vintage::Consolidated > Vintage::Tr);
}
}