reso_dd/generated/
enum_green_energy_generation.rs

1// THIS IS A GENERATED FILE
2// If anything in this file needs to be updated, it needs to be fixed in reso_dd_generator
3use serde::{Deserialize, Serialize};
4
5/// [GreenEnergyGeneration Lookups](https://ddwiki.reso.org/display/DDW17/GreenEnergyGeneration+Lookups)
6#[derive(Debug, Clone, Eq, PartialEq)]
7pub enum GreenEnergyGeneration {
8    /// "[Solar](https://ddwiki.reso.org/display/DDW17/Solar)": Renewable form of onsite power generation. Most common are solar photovoltaic (PV) devices which generate electricity directly from sunlight via an electronic process that occurs naturally in certain types of material, called semiconductors. Powers electrical devices or sends electricity to the grid. See: <a href="http://www.seia.org/policy/solar-technology/photovoltaic-solar-electric">http://www.seia.org/policy/solar-technology/photovoltaic-solar-electric</a>
9    Solar,
10
11    /// "[Wind](https://ddwiki.reso.org/display/DDW17/Wind)": Renewable form of onsite power generation. Wind turbines use wind to make electricity. Powers electrical devices or sends electricity to the grid. See: <a href="http://energy.gov/eere/wind/how-do-wind-turbines-work">http://energy.gov/eere/wind/how-do-wind-turbines-work</a>
12    Wind,
13
14    /// A value that was not defined by the enumeration
15    OpenEnumeration(String),
16}
17
18impl crate::ResoEnumeration for GreenEnergyGeneration {
19    fn from_str(s: &str) -> GreenEnergyGeneration {
20        match s {
21            "Solar" => GreenEnergyGeneration::Solar,
22
23            "Wind" => GreenEnergyGeneration::Wind,
24
25            _ => GreenEnergyGeneration::OpenEnumeration(s.into()),
26        }
27    }
28
29    fn from_string(s: String) -> GreenEnergyGeneration {
30        match s.as_ref() {
31            "Solar" => GreenEnergyGeneration::Solar,
32
33            "Wind" => GreenEnergyGeneration::Wind,
34
35            _ => GreenEnergyGeneration::OpenEnumeration(s),
36        }
37    }
38
39    fn to_str(&self) -> &str {
40        match self {
41            GreenEnergyGeneration::Solar => "Solar",
42
43            GreenEnergyGeneration::Wind => "Wind",
44
45            GreenEnergyGeneration::OpenEnumeration(ref s) => s,
46        }
47    }
48
49    fn into_string(self) -> String {
50        match self {
51            GreenEnergyGeneration::Solar => "Solar".into(),
52
53            GreenEnergyGeneration::Wind => "Wind".into(),
54
55            GreenEnergyGeneration::OpenEnumeration(s) => s,
56        }
57    }
58
59    fn fallback_value(&self) -> Option<&str> {
60        match self {
61            GreenEnergyGeneration::OpenEnumeration(ref s) => Some(s),
62            _ => None,
63        }
64    }
65}
66
67impl From<String> for GreenEnergyGeneration {
68    fn from(s: String) -> GreenEnergyGeneration {
69        match s.as_ref() {
70            "Solar" => GreenEnergyGeneration::Solar,
71
72            "Wind" => GreenEnergyGeneration::Wind,
73
74            _ => GreenEnergyGeneration::OpenEnumeration(s),
75        }
76    }
77}
78
79impl From<&str> for GreenEnergyGeneration {
80    fn from(s: &str) -> GreenEnergyGeneration {
81        match s {
82            "Solar" => GreenEnergyGeneration::Solar,
83
84            "Wind" => GreenEnergyGeneration::Wind,
85
86            _ => GreenEnergyGeneration::OpenEnumeration(s.into()),
87        }
88    }
89}
90
91impl<'a> From<&'a GreenEnergyGeneration> for &'a str {
92    fn from(s: &'a GreenEnergyGeneration) -> &'a str {
93        match s {
94            GreenEnergyGeneration::Solar => "Solar",
95
96            GreenEnergyGeneration::Wind => "Wind",
97
98            GreenEnergyGeneration::OpenEnumeration(s) => s,
99        }
100    }
101}
102
103impl Serialize for GreenEnergyGeneration {
104    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
105    where
106        S: serde::Serializer,
107    {
108        serializer.serialize_str(self.into())
109    }
110}
111
112impl<'de> Deserialize<'de> for GreenEnergyGeneration {
113    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
114    where
115        D: serde::Deserializer<'de>,
116    {
117        let s = String::deserialize(deserializer)?;
118        Ok(From::from(s))
119    }
120}