ed_journals/modules/commander/models/
exploration_rank.rs1use std::fmt::{Display, Formatter};
2
3use serde::Serialize;
4use thiserror::Error;
5
6use crate::try_from_deserialize_impl;
7
8#[derive(Debug, Serialize, Clone, PartialEq)]
9pub enum ExplorationRank {
10 Aimless,
11 MostlyAimless,
12 Scout,
13 Surveyor,
14 Trailblazer,
15 Pathfinder,
16 Ranger,
17 Pioneer,
18 Elite,
19 EliteI,
20 EliteII,
21 EliteIII,
22 EliteIV,
23 EliteV,
24
25 #[cfg(feature = "allow-unknown")]
26 #[cfg_attr(docsrs, doc(cfg(feature = "allow-unknown")))]
27 Unknown(u8),
28}
29
30#[derive(Debug, Error)]
31pub enum ExplorationRankError {
32 #[error("Unknown exploration rank with id '{0}'")]
33 UnknownExplorationRank(u8),
34}
35
36impl TryFrom<u8> for ExplorationRank {
37 type Error = ExplorationRankError;
38
39 fn try_from(value: u8) -> Result<Self, Self::Error> {
40 match value {
41 0 => Ok(ExplorationRank::Aimless),
42 1 => Ok(ExplorationRank::MostlyAimless),
43 2 => Ok(ExplorationRank::Scout),
44 3 => Ok(ExplorationRank::Surveyor),
45 4 => Ok(ExplorationRank::Trailblazer),
46 5 => Ok(ExplorationRank::Pathfinder),
47 6 => Ok(ExplorationRank::Ranger),
48 7 => Ok(ExplorationRank::Pioneer),
49 8 => Ok(ExplorationRank::Elite),
50 9 => Ok(ExplorationRank::EliteI),
51 10 => Ok(ExplorationRank::EliteII),
52 11 => Ok(ExplorationRank::EliteIII),
53 12 => Ok(ExplorationRank::EliteIV),
54 13 => Ok(ExplorationRank::EliteV),
55
56 #[cfg(feature = "allow-unknown")]
57 _ => Ok(ExplorationRank::Unknown(value)),
58
59 #[cfg(not(feature = "allow-unknown"))]
60 _ => Err(ExplorationRankError::UnknownExplorationRank(value)),
61 }
62 }
63}
64
65try_from_deserialize_impl!(u8 => ExplorationRank);
66
67impl Display for ExplorationRank {
68 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
69 write!(
70 f,
71 "{}",
72 match self {
73 ExplorationRank::Aimless => "Aimless",
74 ExplorationRank::MostlyAimless => "Mostly Aimless",
75 ExplorationRank::Scout => "Scout",
76 ExplorationRank::Surveyor => "Surveyor",
77 ExplorationRank::Trailblazer => "Trailblazer",
78 ExplorationRank::Pathfinder => "Pathfinder",
79 ExplorationRank::Ranger => "Ranger",
80 ExplorationRank::Pioneer => "Pioneer",
81 ExplorationRank::Elite => "Elite",
82 ExplorationRank::EliteI => "Elite I",
83 ExplorationRank::EliteII => "Elite II",
84 ExplorationRank::EliteIII => "Elite III",
85 ExplorationRank::EliteIV => "Elite IV",
86 ExplorationRank::EliteV => "Elite V",
87
88 #[cfg(feature = "allow-unknown")]
89 ExplorationRank::Unknown(unknown) =>
90 return write!(f, "Unknown exploration rank nr: {unknown}"),
91 }
92 )
93 }
94}