1use std::str::FromStr;
4
5use strum::IntoEnumIterator;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, strum::EnumIter)]
10#[non_exhaustive]
11pub enum V1 {
12 Zero,
14 One,
16 Two,
18}
19
20impl std::fmt::Display for V1 {
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22 match self {
23 V1::Zero => write!(f, "1.0"),
24 V1::One => write!(f, "1.1"),
25 V1::Two => write!(f, "1.2"),
26 }
27 }
28}
29
30#[derive(
36 Debug,
37 Clone,
38 Copy,
39 PartialEq,
40 Eq,
41 PartialOrd,
42 Ord,
43 serde_with::DeserializeFromStr,
44 serde_with::SerializeDisplay,
45)]
46#[non_exhaustive]
47pub enum SupportedVersion {
48 V1(V1),
50}
51
52impl SupportedVersion {
53 pub fn has_same_major_version(self, other: SupportedVersion) -> bool {
62 match (self, other) {
63 (SupportedVersion::V1(_), SupportedVersion::V1(_)) => true,
64 }
65 }
66
67 pub fn all() -> impl Iterator<Item = Self> {
69 V1::iter().map(Self::V1)
70 }
71}
72
73impl Default for SupportedVersion {
74 fn default() -> Self {
75 Self::V1(V1::Two)
76 }
77}
78
79impl std::fmt::Display for SupportedVersion {
80 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
81 match self {
82 SupportedVersion::V1(version) => write!(f, "{version}"),
83 }
84 }
85}
86
87impl FromStr for SupportedVersion {
88 type Err = String;
89
90 fn from_str(s: &str) -> Result<Self, Self::Err> {
91 match s {
92 "1.0" => Ok(Self::V1(V1::Zero)),
93 "1.1" => Ok(Self::V1(V1::One)),
94 "1.2" => Ok(Self::V1(V1::Two)),
95 _ => Err(s.to_string()),
96 }
97 }
98}