Skip to main content

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#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
12#[cfg_attr(
13    feature = "json-schema",
14    schemars(rename = "TechnischeRessourceNutzung")
15)]
16#[non_exhaustive]
17pub enum TechnicalResourceUsage {
18    /// Electricity consumption type (Stromverbrauchsart)
19    #[serde(rename = "STROMVERBRAUCHSART")]
20    ElectricityConsumptionType,
21
22    /// Electricity generation type (Stromerzeugungsart)
23    #[serde(rename = "STROMERZEUGUNGSART")]
24    ElectricityGenerationType,
25
26    /// Storage (Speicher)
27    #[serde(rename = "SPEICHER")]
28    Storage,
29}
30
31impl TechnicalResourceUsage {
32    /// Returns the German name.
33    pub fn german_name(&self) -> &'static str {
34        match self {
35            Self::ElectricityConsumptionType => "Stromverbrauchsart",
36            Self::ElectricityGenerationType => "Stromerzeugungsart",
37            Self::Storage => "Speicher",
38        }
39    }
40}
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_serialize() {
48        assert_eq!(
49            serde_json::to_string(&TechnicalResourceUsage::Storage).unwrap(),
50            r#""SPEICHER""#
51        );
52    }
53
54    #[test]
55    fn test_roundtrip() {
56        for usage in [
57            TechnicalResourceUsage::ElectricityConsumptionType,
58            TechnicalResourceUsage::ElectricityGenerationType,
59            TechnicalResourceUsage::Storage,
60        ] {
61            let json = serde_json::to_string(&usage).unwrap();
62            let parsed: TechnicalResourceUsage = serde_json::from_str(&json).unwrap();
63            assert_eq!(usage, parsed);
64        }
65    }
66}