Skip to main content

ed_journals/modules/exploration/models/
codex_geological_entry.rs

1use crate::exploration::shared::codex_regex::CODEX_REGEX;
2use crate::from_str_deserialize_impl;
3use serde::Serialize;
4use std::fmt::{Display, Formatter};
5use std::str::FromStr;
6use thiserror::Error;
7
8/// Codex entries related to geological points-of-interest.
9#[derive(Debug, Serialize, Clone, PartialEq, Eq, Hash)]
10#[cfg_attr(not(feature = "allow-unknown"), non_exhaustive)]
11pub enum CodexGeologicalEntry {
12    Fumarole,
13    FumaroleAmmoniaGeysers,
14    FumaroleCarbondioxideGeysers,
15    FumaroleHeliumGeysers,
16    FumaroleMethaneGeysers,
17    FumaroleNitrogenGeysers,
18    FumaroleSilicateVapourGeysers,
19    FumaroleSulfurDioxideMagma,
20    FumaroleWaterGeysers,
21
22    IceFumarole,
23    IceFumaroleAmmoniaGeysers,
24    IceFumaroleCarbonDioxideGeysers,
25    IceFumaroleHeliumGeysers,
26    IceFumaroleMethaneGeysers,
27    IceFumaroleNitrogenGeysers,
28    IceFumaroleSilicateVapourGeysers,
29    IceFumaroleSulfurDioxideMagma,
30    IceFumaroleWaterGeysers,
31
32    GasVents,
33    GasVentsAmmoniaGeysers,
34    GasVentsCarbonDioxideGeysers,
35    GasVentsHeliumGeysers,
36    GasVentsMethaneGeysers,
37    GasVentsNitrogenGeysers,
38    GasVentsSilicateVapourGeysers,
39    GasVentsSulfurDioxideMagma,
40    GasVentsWaterGeysers,
41
42    Geysers,
43    GeysersAmmoniaGeysers,
44    GeysersCarbonDioxideGeysers,
45    GeysersHeliumGeysers,
46    GeysersMethaneGeysers,
47    GeysersNitrogenGeysers,
48    GeysersSulfurDioxideMagma,
49    GeysersWaterGeysers,
50
51    IceGeysers,
52    IceGeysersAmmoniaGeysers,
53    IceGeysersCarbonDioxideGeysers,
54    IceGeysersHeliumGeysers,
55    IceGeysersMethaneGeysers,
56    IceGeysersNitrogenGeysers,
57    IceGeysersSulfurDioxideMagma,
58    IceGeysersWaterGeysers,
59
60    LavaSpouts,
61    LavaSpoutsIronMagma,
62    LavaSpoutsSilicateMagma,
63    LavaSpoutsSulfurDioxideMagma,
64
65    #[cfg(feature = "allow-unknown")]
66    #[cfg_attr(docsrs, doc(cfg(feature = "allow-unknown")))]
67    Unknown(String),
68}
69
70impl CodexGeologicalEntry {
71    /// Whether the current variant is unknown.
72    #[cfg(feature = "allow-unknown")]
73    #[cfg_attr(docsrs, doc(cfg(feature = "allow-unknown")))]
74    pub fn is_unknown(&self) -> bool {
75        matches!(self, CodexGeologicalEntry::Unknown(_))
76    }
77}
78
79#[derive(Debug, Error)]
80pub enum CodexGeologicalError {
81    #[error("Failed to parse geological codex entry: '{0}'")]
82    FailedToParse(String),
83
84    #[error("Unknown geological codex entry: '{0}'")]
85    UnknownEntry(String),
86}
87
88impl FromStr for CodexGeologicalEntry {
89    type Err = CodexGeologicalError;
90
91    fn from_str(s: &str) -> Result<Self, Self::Err> {
92        let Some(captures) = CODEX_REGEX.captures(s) else {
93            return Err(CodexGeologicalError::FailedToParse(s.to_string()));
94        };
95
96        let string: &str = &captures
97            .get(1)
98            .expect("Should have been captured already")
99            .as_str()
100            .to_ascii_lowercase();
101
102        Ok(match string {
103            "fumarole" => CodexGeologicalEntry::Fumarole,
104            "fumarole_ammoniageysers" => CodexGeologicalEntry::FumaroleAmmoniaGeysers,
105            "fumarole_carbondioxidegeysers" => CodexGeologicalEntry::FumaroleCarbondioxideGeysers,
106            "fumarole_heliumgeysers" => CodexGeologicalEntry::FumaroleHeliumGeysers,
107            "fumarole_methanegeysers" => CodexGeologicalEntry::FumaroleMethaneGeysers,
108            "fumarole_nitrogengeysers" => CodexGeologicalEntry::FumaroleNitrogenGeysers,
109            "fumarole_silicatevapourgeysers" => CodexGeologicalEntry::FumaroleSilicateVapourGeysers,
110            "fumarole_sulphurdioxidemagma" => CodexGeologicalEntry::FumaroleSulfurDioxideMagma,
111            "fumarole_watergeysers" => CodexGeologicalEntry::FumaroleWaterGeysers,
112
113            "icefumarole" => CodexGeologicalEntry::IceFumarole,
114            "icefumarole_ammoniageysers" => CodexGeologicalEntry::IceFumaroleAmmoniaGeysers,
115            "icefumarole_carbondioxidegeysers" => {
116                CodexGeologicalEntry::IceFumaroleCarbonDioxideGeysers
117            }
118            "icefumarole_heliumgeysers" => CodexGeologicalEntry::IceFumaroleHeliumGeysers,
119            "icefumarole_methanegeysers" => CodexGeologicalEntry::IceFumaroleMethaneGeysers,
120            "icefumarole_nitrogengeysers" => CodexGeologicalEntry::IceFumaroleNitrogenGeysers,
121            "icefumarole_silicatevapourgeysers" => {
122                CodexGeologicalEntry::IceFumaroleSilicateVapourGeysers
123            }
124            "icefumarole_sulphurdioxidemagma" => {
125                CodexGeologicalEntry::IceFumaroleSulfurDioxideMagma
126            }
127            "icefumarole_watergeysers" => CodexGeologicalEntry::IceFumaroleWaterGeysers,
128
129            "gas_vents" => CodexGeologicalEntry::GasVents,
130            "gas_vents_ammoniageysers" => CodexGeologicalEntry::GasVentsAmmoniaGeysers,
131            "gas_vents_carbondioxidegeysers" => CodexGeologicalEntry::GasVentsCarbonDioxideGeysers,
132            "gas_vents_heliumgeysers" => CodexGeologicalEntry::GasVentsHeliumGeysers,
133            "gas_vents_methanegeysers" => CodexGeologicalEntry::GasVentsMethaneGeysers,
134            "gas_vents_nitrogengeysers" => CodexGeologicalEntry::GasVentsNitrogenGeysers,
135            "gas_vents_silicatevapourgeysers" => {
136                CodexGeologicalEntry::GasVentsSilicateVapourGeysers
137            }
138            "gas_vents_sulphurdioxidemagma" => CodexGeologicalEntry::GasVentsSulfurDioxideMagma,
139            "gas_vents_watergeysers" => CodexGeologicalEntry::GasVentsWaterGeysers,
140
141            "geysers" => CodexGeologicalEntry::Geysers,
142            "geysers_ammoniageysers" => CodexGeologicalEntry::GeysersAmmoniaGeysers,
143            "geysers_carbondioxidegeysers" => CodexGeologicalEntry::GeysersCarbonDioxideGeysers,
144            "geysers_heliumgeysers" => CodexGeologicalEntry::GeysersHeliumGeysers,
145            "geysers_methanegeysers" => CodexGeologicalEntry::GeysersMethaneGeysers,
146            "geysers_nitrogengeysers" => CodexGeologicalEntry::GeysersNitrogenGeysers,
147            "geysers_sulphurdioxidemagma" => CodexGeologicalEntry::GeysersSulfurDioxideMagma,
148            "geysers_watergeysers" => CodexGeologicalEntry::GeysersWaterGeysers,
149
150            "icegeysers" => CodexGeologicalEntry::IceGeysers,
151            "icegeysers_ammoniageysers" => CodexGeologicalEntry::IceGeysersAmmoniaGeysers,
152            "icegeysers_carbondioxidegeysers" => {
153                CodexGeologicalEntry::IceGeysersCarbonDioxideGeysers
154            }
155            "icegeysers_heliumgeysers" => CodexGeologicalEntry::IceGeysersHeliumGeysers,
156            "icegeysers_methanegeysers" => CodexGeologicalEntry::IceGeysersMethaneGeysers,
157            "icegeysers_nitrogengeysers" => CodexGeologicalEntry::IceGeysersNitrogenGeysers,
158            "icegeysers_sulphurdioxidemagma" => CodexGeologicalEntry::IceGeysersSulfurDioxideMagma,
159            "icegeysers_watergeysers" => CodexGeologicalEntry::IceGeysersWaterGeysers,
160
161            "lava_spouts" => CodexGeologicalEntry::LavaSpouts,
162            "lava_spouts_ironmagma" => CodexGeologicalEntry::LavaSpoutsIronMagma,
163            "lava_spouts_silicatemagma" => CodexGeologicalEntry::LavaSpoutsSilicateMagma,
164            "lava_spouts_sulphurdioxidemagma" => CodexGeologicalEntry::LavaSpoutsSulfurDioxideMagma,
165
166            #[cfg(feature = "allow-unknown")]
167            _ => CodexGeologicalEntry::Unknown(string.to_string()),
168
169            #[cfg(not(feature = "allow-unknown"))]
170            _ => return Err(CodexGeologicalError::UnknownEntry(string.to_string())),
171        })
172    }
173}
174
175from_str_deserialize_impl!(CodexGeologicalEntry);
176
177impl Display for CodexGeologicalEntry {
178    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
179        write!(
180            f,
181            "{}",
182            match self {
183                CodexGeologicalEntry::Fumarole => "Fumarole",
184                CodexGeologicalEntry::FumaroleAmmoniaGeysers => "Ammonia Fumarole",
185                CodexGeologicalEntry::FumaroleCarbondioxideGeysers => "Carbon Dioxide Fumarole",
186                CodexGeologicalEntry::FumaroleHeliumGeysers => "Helium Fumarole",
187                CodexGeologicalEntry::FumaroleMethaneGeysers => "Methane Fumarole",
188                CodexGeologicalEntry::FumaroleNitrogenGeysers => "Nitrogen Fumarole",
189                CodexGeologicalEntry::FumaroleSilicateVapourGeysers => "Silicate Vapour Fumarole",
190                CodexGeologicalEntry::FumaroleSulfurDioxideMagma => "Sulfur Dioxide Fumarole",
191                CodexGeologicalEntry::FumaroleWaterGeysers => "Water Geysers Fumarole",
192
193                CodexGeologicalEntry::IceFumarole => "Ice Fumarole",
194                CodexGeologicalEntry::IceFumaroleAmmoniaGeysers => "Ammonia Ice Fumarole",
195                CodexGeologicalEntry::IceFumaroleCarbonDioxideGeysers =>
196                    "Carbon Dioxide Ice Fumarole",
197                CodexGeologicalEntry::IceFumaroleHeliumGeysers => "Helium Ice Fumarole",
198                CodexGeologicalEntry::IceFumaroleMethaneGeysers => "Methane Ice Fumarole",
199                CodexGeologicalEntry::IceFumaroleNitrogenGeysers => "Nitrogen Ice Fumarole",
200                CodexGeologicalEntry::IceFumaroleSilicateVapourGeysers =>
201                    "Silicate Vapour Ice Fumarole",
202                CodexGeologicalEntry::IceFumaroleSulfurDioxideMagma =>
203                    "Sulfur Dioxide Ice Fumarole",
204                CodexGeologicalEntry::IceFumaroleWaterGeysers => "Water Geysers Ice Fumarole",
205
206                CodexGeologicalEntry::GasVents => "Gas Vents",
207                CodexGeologicalEntry::GasVentsAmmoniaGeysers => "Ammonia Gas Vents",
208                CodexGeologicalEntry::GasVentsCarbonDioxideGeysers => "Carbon Dioxide Gas Vents",
209                CodexGeologicalEntry::GasVentsHeliumGeysers => "Helium Gas Vents",
210                CodexGeologicalEntry::GasVentsMethaneGeysers => "Methane Gas Vents",
211                CodexGeologicalEntry::GasVentsNitrogenGeysers => "Nitrogen Gas Vents",
212                CodexGeologicalEntry::GasVentsSilicateVapourGeysers => "Silicate Vapour Gas Vents",
213                CodexGeologicalEntry::GasVentsSulfurDioxideMagma => "Sulfur Dioxide Gas Vents",
214                CodexGeologicalEntry::GasVentsWaterGeysers => "Water Gas Vents",
215
216                CodexGeologicalEntry::Geysers => "Geysers",
217                CodexGeologicalEntry::GeysersAmmoniaGeysers => "Ammonia Geysers",
218                CodexGeologicalEntry::GeysersCarbonDioxideGeysers => "Carbon Dioxide Geysers",
219                CodexGeologicalEntry::GeysersHeliumGeysers => "Helium Geysers",
220                CodexGeologicalEntry::GeysersMethaneGeysers => "Methane Geysers",
221                CodexGeologicalEntry::GeysersNitrogenGeysers => "Nitrogen Geysers",
222                CodexGeologicalEntry::GeysersSulfurDioxideMagma => "Sulfur Dioxide Geysers",
223                CodexGeologicalEntry::GeysersWaterGeysers => "Water Geysers",
224
225                CodexGeologicalEntry::IceGeysers => "Ice Geysers",
226                CodexGeologicalEntry::IceGeysersAmmoniaGeysers => "Ammonia Ice Geysers",
227                CodexGeologicalEntry::IceGeysersCarbonDioxideGeysers =>
228                    "Carbon Dioxide Ice Geysers",
229                CodexGeologicalEntry::IceGeysersHeliumGeysers => "Helium Ice Geysers",
230                CodexGeologicalEntry::IceGeysersMethaneGeysers => "Methane Ice Geysers",
231                CodexGeologicalEntry::IceGeysersNitrogenGeysers => "Nitrogen Ice Geysers",
232                CodexGeologicalEntry::IceGeysersSulfurDioxideMagma => "Sulfur Dioxide Ice Geysers",
233                CodexGeologicalEntry::IceGeysersWaterGeysers => "Water Ice Geysers",
234
235                CodexGeologicalEntry::LavaSpouts => "Lava Spouts",
236                CodexGeologicalEntry::LavaSpoutsIronMagma => "Iron Magma Lava Spouts",
237                CodexGeologicalEntry::LavaSpoutsSilicateMagma => "Silicate Magma Lava Spouts",
238                CodexGeologicalEntry::LavaSpoutsSulfurDioxideMagma =>
239                    "Sulfur Dioxide Magma Lava Spouts",
240
241                #[cfg(feature = "allow-unknown")]
242                CodexGeologicalEntry::Unknown(unknown) =>
243                    return write!(f, "Unknown geological codex entry: {unknown}"),
244            }
245        )
246    }
247}