bo4e_core/enums/
technical_resource_usage.rs

1//! Technical resource usage (TechnischeRessourceNutzung) enumeration.
2
3use serde::{Deserialize, Serialize};
4
5/// Usage type of a technical resource.
6///
7/// Describes how a technical resource is used in the energy system.
8///
9/// German: TechnischeRessourceNutzung
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
11#[non_exhaustive]
12pub enum TechnicalResourceUsage {
13    /// Electricity consumption type (Stromverbrauchsart)
14    #[serde(rename = "STROMVERBRAUCHSART")]
15    ElectricityConsumptionType,
16
17    /// Electricity generation type (Stromerzeugungsart)
18    #[serde(rename = "STROMERZEUGUNGSART")]
19    ElectricityGenerationType,
20
21    /// Storage (Speicher)
22    #[serde(rename = "SPEICHER")]
23    Storage,
24}
25
26impl TechnicalResourceUsage {
27    /// Returns the German name.
28    pub fn german_name(&self) -> &'static str {
29        match self {
30            Self::ElectricityConsumptionType => "Stromverbrauchsart",
31            Self::ElectricityGenerationType => "Stromerzeugungsart",
32            Self::Storage => "Speicher",
33        }
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40
41    #[test]
42    fn test_serialize() {
43        assert_eq!(
44            serde_json::to_string(&TechnicalResourceUsage::Storage).unwrap(),
45            r#""SPEICHER""#
46        );
47    }
48
49    #[test]
50    fn test_roundtrip() {
51        for usage in [
52            TechnicalResourceUsage::ElectricityConsumptionType,
53            TechnicalResourceUsage::ElectricityGenerationType,
54            TechnicalResourceUsage::Storage,
55        ] {
56            let json = serde_json::to_string(&usage).unwrap();
57            let parsed: TechnicalResourceUsage = serde_json::from_str(&json).unwrap();
58            assert_eq!(usage, parsed);
59        }
60    }
61}