ed_journals/modules/exploration/models/
codex_geological_entry.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
use crate::exploration::shared::codex_regex::CODEX_REGEX;
use crate::from_str_deserialize_impl;
use serde::Serialize;
use std::fmt::{Display, Formatter};
use std::str::FromStr;
use thiserror::Error;

/// Codex entries related to geological points-of-interest.
#[derive(Debug, Serialize, Clone, PartialEq, Eq, Hash)]
pub enum CodexGeologicalEntry {
    Fumarole,
    FumaroleAmmoniaGeysers,
    FumaroleCarbondioxideGeysers,
    FumaroleHeliumGeysers,
    FumaroleMethaneGeysers,
    FumaroleNitrogenGeysers,
    FumaroleSilicateVapourGeysers,
    FumaroleSulfurDioxideMagma,
    FumaroleWaterGeysers,

    IceFumarole,
    IceFumaroleAmmoniaGeysers,
    IceFumaroleCarbonDioxideGeysers,
    IceFumaroleHeliumGeysers,
    IceFumaroleMethaneGeysers,
    IceFumaroleNitrogenGeysers,
    IceFumaroleSilicateVapourGeysers,
    IceFumaroleSulfurDioxideMagma,
    IceFumaroleWaterGeysers,

    GasVents,
    GasVentsAmmoniaGeysers,
    GasVentsCarbonDioxideGeysers,
    GasVentsHeliumGeysers,
    GasVentsMethaneGeysers,
    GasVentsNitrogenGeysers,
    GasVentsSilicateVapourGeysers,
    GasVentsSulfurDioxideMagma,
    GasVentsWaterGeysers,

    Geysers,
    GeysersAmmoniaGeysers,
    GeysersCarbonDioxideGeysers,
    GeysersHeliumGeysers,
    GeysersMethaneGeysers,
    GeysersNitrogenGeysers,
    GeysersSulfurDioxideMagma,
    GeysersWaterGeysers,

    IceGeysers,
    IceGeysersAmmoniaGeysers,
    IceGeysersCarbonDioxideGeysers,
    IceGeysersHeliumGeysers,
    IceGeysersMethaneGeysers,
    IceGeysersNitrogenGeysers,
    IceGeysersSulfurDioxideMagma,
    IceGeysersWaterGeysers,

    LavaSpouts,
    LavaSpoutsIronMagma,
    LavaSpoutsSilicateMagma,
    LavaSpoutsSulfurDioxideMagma,

    #[cfg(feature = "allow-unknown")]
    #[cfg_attr(docsrs, doc(cfg(feature = "allow-unknown")))]
    Unknown(String),
}

impl CodexGeologicalEntry {
    /// Whether the current variant is unknown.
    #[cfg(feature = "allow-unknown")]
    #[cfg_attr(docsrs, doc(cfg(feature = "allow-unknown")))]
    pub fn is_unknown(&self) -> bool {
        matches!(self, CodexGeologicalEntry::Unknown(_))
    }
}

#[derive(Debug, Error)]
pub enum CodexGeologicalError {
    #[error("Failed to parse geological codex entry: '{0}'")]
    FailedToParse(String),

    #[error("Unknown geological codex entry: '{0}'")]
    UnknownEntry(String),
}

impl FromStr for CodexGeologicalEntry {
    type Err = CodexGeologicalError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let Some(captures) = CODEX_REGEX.captures(s) else {
            return Err(CodexGeologicalError::FailedToParse(s.to_string()));
        };

        let string: &str = &captures
            .get(1)
            .expect("Should have been captured already")
            .as_str()
            .to_ascii_lowercase();

        Ok(match string {
            "fumarole" => CodexGeologicalEntry::Fumarole,
            "fumarole_ammoniageysers" => CodexGeologicalEntry::FumaroleAmmoniaGeysers,
            "fumarole_carbondioxidegeysers" => CodexGeologicalEntry::FumaroleCarbondioxideGeysers,
            "fumarole_heliumgeysers" => CodexGeologicalEntry::FumaroleHeliumGeysers,
            "fumarole_methanegeysers" => CodexGeologicalEntry::FumaroleMethaneGeysers,
            "fumarole_nitrogengeysers" => CodexGeologicalEntry::FumaroleNitrogenGeysers,
            "fumarole_silicatevapourgeysers" => CodexGeologicalEntry::FumaroleSilicateVapourGeysers,
            "fumarole_sulphurdioxidemagma" => CodexGeologicalEntry::FumaroleSulfurDioxideMagma,
            "fumarole_watergeysers" => CodexGeologicalEntry::FumaroleWaterGeysers,

            "icefumarole" => CodexGeologicalEntry::IceFumarole,
            "icefumarole_ammoniageysers" => CodexGeologicalEntry::IceFumaroleAmmoniaGeysers,
            "icefumarole_carbondioxidegeysers" => {
                CodexGeologicalEntry::IceFumaroleCarbonDioxideGeysers
            }
            "icefumarole_heliumgeysers" => CodexGeologicalEntry::IceFumaroleHeliumGeysers,
            "icefumarole_methanegeysers" => CodexGeologicalEntry::IceFumaroleMethaneGeysers,
            "icefumarole_nitrogengeysers" => CodexGeologicalEntry::IceFumaroleNitrogenGeysers,
            "icefumarole_silicatevapourgeysers" => {
                CodexGeologicalEntry::IceFumaroleSilicateVapourGeysers
            }
            "icefumarole_sulphurdioxidemagma" => {
                CodexGeologicalEntry::IceFumaroleSulfurDioxideMagma
            }
            "icefumarole_watergeysers" => CodexGeologicalEntry::IceFumaroleWaterGeysers,

            "gas_vents" => CodexGeologicalEntry::GasVents,
            "gas_vents_ammoniageysers" => CodexGeologicalEntry::GasVentsAmmoniaGeysers,
            "gas_vents_carbondioxidegeysers" => CodexGeologicalEntry::GasVentsCarbonDioxideGeysers,
            "gas_vents_heliumgeysers" => CodexGeologicalEntry::GasVentsHeliumGeysers,
            "gas_vents_methanegeysers" => CodexGeologicalEntry::GasVentsMethaneGeysers,
            "gas_vents_nitrogengeysers" => CodexGeologicalEntry::GasVentsNitrogenGeysers,
            "gas_vents_silicatevapourgeysers" => {
                CodexGeologicalEntry::GasVentsSilicateVapourGeysers
            }
            "gas_vents_sulphurdioxidemagma" => CodexGeologicalEntry::GasVentsSulfurDioxideMagma,
            "gas_vents_watergeysers" => CodexGeologicalEntry::GasVentsWaterGeysers,

            "geysers" => CodexGeologicalEntry::Geysers,
            "geysers_ammoniageysers" => CodexGeologicalEntry::GeysersAmmoniaGeysers,
            "geysers_carbondioxidegeysers" => CodexGeologicalEntry::GeysersCarbonDioxideGeysers,
            "geysers_heliumgeysers" => CodexGeologicalEntry::GeysersHeliumGeysers,
            "geysers_methanegeysers" => CodexGeologicalEntry::GeysersMethaneGeysers,
            "geysers_nitrogengeysers" => CodexGeologicalEntry::GeysersNitrogenGeysers,
            "geysers_sulphurdioxidemagma" => CodexGeologicalEntry::GeysersSulfurDioxideMagma,
            "geysers_watergeysers" => CodexGeologicalEntry::GeysersWaterGeysers,

            "icegeysers" => CodexGeologicalEntry::IceGeysers,
            "icegeysers_ammoniageysers" => CodexGeologicalEntry::IceGeysersAmmoniaGeysers,
            "icegeysers_carbondioxidegeysers" => {
                CodexGeologicalEntry::IceGeysersCarbonDioxideGeysers
            }
            "icegeysers_heliumgeysers" => CodexGeologicalEntry::IceGeysersHeliumGeysers,
            "icegeysers_methanegeysers" => CodexGeologicalEntry::IceGeysersMethaneGeysers,
            "icegeysers_nitrogengeysers" => CodexGeologicalEntry::IceGeysersNitrogenGeysers,
            "icegeysers_sulphurdioxidemagma" => CodexGeologicalEntry::IceGeysersSulfurDioxideMagma,
            "icegeysers_watergeysers" => CodexGeologicalEntry::IceGeysersWaterGeysers,

            "lava_spouts" => CodexGeologicalEntry::LavaSpouts,
            "lava_spouts_ironmagma" => CodexGeologicalEntry::LavaSpoutsIronMagma,
            "lava_spouts_silicatemagma" => CodexGeologicalEntry::LavaSpoutsSilicateMagma,
            "lava_spouts_sulphurdioxidemagma" => CodexGeologicalEntry::LavaSpoutsSulfurDioxideMagma,

            #[cfg(feature = "allow-unknown")]
            _ => CodexGeologicalEntry::Unknown(string.to_string()),

            #[cfg(not(feature = "allow-unknown"))]
            _ => return Err(CodexGeologicalError::UnknownEntry(string.to_string())),
        })
    }
}

from_str_deserialize_impl!(CodexGeologicalEntry);

impl Display for CodexGeologicalEntry {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "{}",
            match self {
                CodexGeologicalEntry::Fumarole => "Fumarole",
                CodexGeologicalEntry::FumaroleAmmoniaGeysers => "Ammonia Fumarole",
                CodexGeologicalEntry::FumaroleCarbondioxideGeysers => "Carbon Dioxide Fumarole",
                CodexGeologicalEntry::FumaroleHeliumGeysers => "Helium Fumarole",
                CodexGeologicalEntry::FumaroleMethaneGeysers => "Methane Fumarole",
                CodexGeologicalEntry::FumaroleNitrogenGeysers => "Nitrogen Fumarole",
                CodexGeologicalEntry::FumaroleSilicateVapourGeysers => "Silicate Vapour Fumarole",
                CodexGeologicalEntry::FumaroleSulfurDioxideMagma => "Sulfur Dioxide Fumarole",
                CodexGeologicalEntry::FumaroleWaterGeysers => "Water Geysers Fumarole",

                CodexGeologicalEntry::IceFumarole => "Ice Fumarole",
                CodexGeologicalEntry::IceFumaroleAmmoniaGeysers => "Ammonia Ice Fumarole",
                CodexGeologicalEntry::IceFumaroleCarbonDioxideGeysers =>
                    "Carbon Dioxide Ice Fumarole",
                CodexGeologicalEntry::IceFumaroleHeliumGeysers => "Helium Ice Fumarole",
                CodexGeologicalEntry::IceFumaroleMethaneGeysers => "Methane Ice Fumarole",
                CodexGeologicalEntry::IceFumaroleNitrogenGeysers => "Nitrogen Ice Fumarole",
                CodexGeologicalEntry::IceFumaroleSilicateVapourGeysers =>
                    "Silicate Vapour Ice Fumarole",
                CodexGeologicalEntry::IceFumaroleSulfurDioxideMagma =>
                    "Sulfur Dioxide Ice Fumarole",
                CodexGeologicalEntry::IceFumaroleWaterGeysers => "Water Geysers Ice Fumarole",

                CodexGeologicalEntry::GasVents => "Gas Vents",
                CodexGeologicalEntry::GasVentsAmmoniaGeysers => "Ammonia Gas Vents",
                CodexGeologicalEntry::GasVentsCarbonDioxideGeysers => "Carbon Dioxide Gas Vents",
                CodexGeologicalEntry::GasVentsHeliumGeysers => "Helium Gas Vents",
                CodexGeologicalEntry::GasVentsMethaneGeysers => "Methane Gas Vents",
                CodexGeologicalEntry::GasVentsNitrogenGeysers => "Nitrogen Gas Vents",
                CodexGeologicalEntry::GasVentsSilicateVapourGeysers => "Silicate Vapour Gas Vents",
                CodexGeologicalEntry::GasVentsSulfurDioxideMagma => "Sulfur Dioxide Gas Vents",
                CodexGeologicalEntry::GasVentsWaterGeysers => "Water Gas Vents",

                CodexGeologicalEntry::Geysers => "Geysers",
                CodexGeologicalEntry::GeysersAmmoniaGeysers => "Ammonia Geysers",
                CodexGeologicalEntry::GeysersCarbonDioxideGeysers => "Carbon Dioxide Geysers",
                CodexGeologicalEntry::GeysersHeliumGeysers => "Helium Geysers",
                CodexGeologicalEntry::GeysersMethaneGeysers => "Methane Geysers",
                CodexGeologicalEntry::GeysersNitrogenGeysers => "Nitrogen Geysers",
                CodexGeologicalEntry::GeysersSulfurDioxideMagma => "Sulfur Dioxide Geysers",
                CodexGeologicalEntry::GeysersWaterGeysers => "Water Geysers",

                CodexGeologicalEntry::IceGeysers => "Ice Geysers",
                CodexGeologicalEntry::IceGeysersAmmoniaGeysers => "Ammonia Ice Geysers",
                CodexGeologicalEntry::IceGeysersCarbonDioxideGeysers =>
                    "Carbon Dioxide Ice Geysers",
                CodexGeologicalEntry::IceGeysersHeliumGeysers => "Helium Ice Geysers",
                CodexGeologicalEntry::IceGeysersMethaneGeysers => "Methane Ice Geysers",
                CodexGeologicalEntry::IceGeysersNitrogenGeysers => "Nitrogen Ice Geysers",
                CodexGeologicalEntry::IceGeysersSulfurDioxideMagma => "Sulfur Dioxide Ice Geysers",
                CodexGeologicalEntry::IceGeysersWaterGeysers => "Water Ice Geysers",

                CodexGeologicalEntry::LavaSpouts => "Lava Spouts",
                CodexGeologicalEntry::LavaSpoutsIronMagma => "Iron Magma Lava Spouts",
                CodexGeologicalEntry::LavaSpoutsSilicateMagma => "Silicate Magma Lava Spouts",
                CodexGeologicalEntry::LavaSpoutsSulfurDioxideMagma =>
                    "Sulfur Dioxide Magma Lava Spouts",

                #[cfg(feature = "allow-unknown")]
                CodexGeologicalEntry::Unknown(unknown) =>
                    return write!(f, "Unknown geological codex entry: {}", unknown),
            }
        )
    }
}