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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use std::str::FromStr;
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum AlertStatus {
#[serde(rename = "Actual")]
Actual,
#[serde(rename = "Exercise")]
Exercise,
#[serde(rename = "System")]
System,
#[serde(rename = "Test")]
Test,
#[serde(rename = "Draft")]
Draft,
}
impl std::fmt::Display for AlertStatus {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Actual => write!(f, "actual"),
Self::Exercise => write!(f, "exercise"),
Self::System => write!(f, "system"),
Self::Test => write!(f, "test"),
Self::Draft => write!(f, "draft"),
}
}
}
impl FromStr for AlertStatus {
type Err = String;
/// Parse a string into an [`AlertStatus`].
///
/// # Examples
///
/// ```
/// use std::str::FromStr;
/// use noaa_weather_client::models::AlertStatus;
///
/// let status = AlertStatus::from_str("actual").unwrap();
/// assert_eq!(status, AlertStatus::Actual);
/// ```
///
/// ```
/// use std::str::FromStr;
/// use noaa_weather_client::models::AlertStatus;
///
/// let status = AlertStatus::from_str("ACTUAL").unwrap();
/// assert_eq!(status, AlertStatus::Actual);
/// ```
///
/// # Errors
///
/// Returns an error if the string is not a valid alert status.
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"actual" => Ok(Self::Actual),
"exercise" => Ok(Self::Exercise),
"system" => Ok(Self::System),
"test" => Ok(Self::Test),
"draft" => Ok(Self::Draft),
_ => Err(format!("Invalid alert status: {s}")),
}
}
}