Skip to main content

ed_journals/modules/civilization/models/
system_security.rs

1use std::fmt::{Display, Formatter};
2
3use serde::{Deserialize, Serialize};
4
5/// The level of security present in a system which controls how much security force is present in
6/// the system.
7#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
8pub enum SystemSecurity {
9    #[serde(rename = "$SYSTEM_SECURITY_high;")]
10    High,
11
12    #[serde(rename = "$SYSTEM_SECURITY_medium;")]
13    Medium,
14
15    #[serde(rename = "$SYSTEM_SECURITY_low;")]
16    Low,
17
18    #[serde(rename = "$GAlAXY_MAP_INFO_state_anarchy;")]
19    Anarchy,
20
21    #[serde(rename = "$GALAXY_MAP_INFO_state_lawless;")]
22    Lawless,
23
24    #[cfg(feature = "allow-unknown")]
25    #[cfg_attr(docsrs, doc(cfg(feature = "allow-unknown")))]
26    #[serde(untagged)]
27    Unknown(String),
28}
29
30impl Display for SystemSecurity {
31    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
32        write!(
33            f,
34            "{}",
35            match self {
36                SystemSecurity::High => "High",
37                SystemSecurity::Medium => "Medium",
38                SystemSecurity::Low => "Low",
39                SystemSecurity::Anarchy => "Anarchy",
40                SystemSecurity::Lawless => "Lawless",
41
42                #[cfg(feature = "allow-unknown")]
43                SystemSecurity::Unknown(unknown) =>
44                    return write!(f, "Unknown system security: {unknown}"),
45            }
46        )
47    }
48}