1use std::{fmt, str::FromStr};
6
7use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
11#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
12pub enum Edition {
13 #[serde(rename = "2014")]
14 Rules2014,
15 #[default]
18 #[serde(rename = "2024")]
19 Rules2024,
20}
21
22impl fmt::Display for Edition {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 f.write_str(match self {
25 Edition::Rules2014 => "2014",
26 Edition::Rules2024 => "2024",
27 })
28 }
29}
30
31#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
33#[error("unknown edition \"{0}\"; use 2014 or 2024")]
34pub struct UnknownEdition(String);
35
36impl FromStr for Edition {
37 type Err = UnknownEdition;
38
39 fn from_str(s: &str) -> Result<Self, Self::Err> {
40 match s.trim() {
41 "2014" => Ok(Edition::Rules2014),
42 "2024" => Ok(Edition::Rules2024),
43 other => Err(UnknownEdition(other.to_string())),
44 }
45 }
46}