ed_journals/modules/civilization/models/
superpower.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
use std::fmt::{Display, Formatter};

use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum Superpower {
    Alliance,
    Empire,
    Federation,
    Guardian,
    Independent,
    PilotsFederation,
    PlayerPilots,
    Thargoid,

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

impl Display for Superpower {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "{}",
            match self {
                Superpower::Alliance => "Alliance",
                Superpower::Empire => "Empire",
                Superpower::Federation => "Federation",
                Superpower::Guardian => "Guardian",
                Superpower::Independent => "Independent",
                Superpower::PilotsFederation => "Pilots Federation",
                Superpower::PlayerPilots => "Player Pilots",
                Superpower::Thargoid => "Thargoid",

                #[cfg(feature = "allow-unknown")]
                Superpower::Unknown(unknown) =>
                    return write!(f, "Unknown superpower: {}", unknown),
            }
        )
    }
}