bo4e_core/enums/
division.rs

1//! Energy division (Sparte) enumeration.
2
3use serde::{Deserialize, Serialize};
4
5/// Energy division/sector.
6///
7/// Indicates which energy sector a business object belongs to.
8///
9/// German: Sparte
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
11#[non_exhaustive]
12pub enum Division {
13    /// Electricity (Strom)
14    #[serde(rename = "STROM")]
15    Electricity,
16
17    /// Natural gas (Gas)
18    #[serde(rename = "GAS")]
19    Gas,
20
21    /// District heating (Fernwaerme)
22    #[serde(rename = "FERNWAERME")]
23    DistrictHeating,
24
25    /// Local/near heating (Nahwaerme)
26    #[serde(rename = "NAHWAERME")]
27    LocalHeating,
28
29    /// Water (Wasser)
30    #[serde(rename = "WASSER")]
31    Water,
32
33    /// Wastewater (Abwasser)
34    #[serde(rename = "ABWASSER")]
35    Wastewater,
36
37    /// Cross-divisional electricity and gas (Strom und Gas)
38    #[serde(rename = "STROM_UND_GAS")]
39    ElectricityAndGas,
40}
41
42impl Division {
43    /// Returns the German name.
44    pub fn german_name(&self) -> &'static str {
45        match self {
46            Self::Electricity => "Strom",
47            Self::Gas => "Gas",
48            Self::DistrictHeating => "Fernwaerme",
49            Self::LocalHeating => "Nahwaerme",
50            Self::Water => "Wasser",
51            Self::Wastewater => "Abwasser",
52            Self::ElectricityAndGas => "Strom und Gas",
53        }
54    }
55}
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_serialize() {
63        assert_eq!(
64            serde_json::to_string(&Division::Electricity).unwrap(),
65            r#""STROM""#
66        );
67        assert_eq!(serde_json::to_string(&Division::Gas).unwrap(), r#""GAS""#);
68    }
69
70    #[test]
71    fn test_deserialize() {
72        assert_eq!(
73            serde_json::from_str::<Division>(r#""STROM""#).unwrap(),
74            Division::Electricity
75        );
76        assert_eq!(
77            serde_json::from_str::<Division>(r#""FERNWAERME""#).unwrap(),
78            Division::DistrictHeating
79        );
80    }
81
82    #[test]
83    fn test_roundtrip() {
84        for division in [
85            Division::Electricity,
86            Division::Gas,
87            Division::DistrictHeating,
88            Division::LocalHeating,
89            Division::Water,
90            Division::Wastewater,
91            Division::ElectricityAndGas,
92        ] {
93            let json = serde_json::to_string(&division).unwrap();
94            let parsed: Division = serde_json::from_str(&json).unwrap();
95            assert_eq!(division, parsed);
96        }
97    }
98}