lsp_max_protocol/
policy.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
8pub enum PolicyState {
9 Operational,
10 ClarificationRequested,
11 RefundAuthorized,
12 Active,
14}
15
16impl std::str::FromStr for PolicyState {
17 type Err = String;
18 fn from_str(s: &str) -> Result<Self, Self::Err> {
19 match s {
20 "Operational" => Ok(Self::Operational),
21 "ClarificationRequested" => Ok(Self::ClarificationRequested),
22 "RefundAuthorized" => Ok(Self::RefundAuthorized),
23 "Active" => Ok(Self::Active),
24 other => Err(format!("Unknown policy state: {other}")),
25 }
26 }
27}
28
29impl std::fmt::Display for PolicyState {
30 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31 match self {
32 PolicyState::Operational => write!(f, "Operational"),
33 PolicyState::ClarificationRequested => write!(f, "ClarificationRequested"),
34 PolicyState::RefundAuthorized => write!(f, "RefundAuthorized"),
35 PolicyState::Active => write!(f, "Active"),
36 }
37 }
38}
39
40#[cfg(test)]
41mod policy_state_tests {
42 use super::PolicyState;
43 #[test]
44 fn test_policy_state_from_str_roundtrip() {
45 assert_eq!(
46 "Operational".parse::<PolicyState>(),
47 Ok(PolicyState::Operational)
48 );
49 assert_eq!(
50 "ClarificationRequested".parse::<PolicyState>(),
51 Ok(PolicyState::ClarificationRequested)
52 );
53 assert_eq!(
54 "RefundAuthorized".parse::<PolicyState>(),
55 Ok(PolicyState::RefundAuthorized)
56 );
57 assert!("Bogus".parse::<PolicyState>().is_err());
58 }
59}