1use std::str::FromStr;
2
3pub mod consts;
4pub mod mcp;
5pub mod port;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
8pub enum ProtocolVersion {
9 V20241105,
10 V20250326,
11}
12
13impl FromStr for ProtocolVersion {
14 type Err = anyhow::Error;
15
16 fn from_str(s: &str) -> Result<Self, Self::Err> {
17 Ok(match s {
18 "2024-11-05" => Self::V20241105,
19 "2025-03-26" => Self::V20250326,
20 _ => return Err(anyhow::anyhow!("invalid protocol version: {}", s)),
21 })
22 }
23}
24
25impl std::fmt::Display for ProtocolVersion {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 match self {
28 Self::V20241105 => write!(f, "2024-11-05"),
29 Self::V20250326 => write!(f, "2025-03-26"),
30 }
31 }
32}
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37
38 #[test]
39 fn test_protocol_version() {
40 assert_eq!(ProtocolVersion::V20241105.to_string(), "2024-11-05");
42 assert_eq!(ProtocolVersion::V20250326.to_string(), "2025-03-26");
43
44 assert_eq!(
46 "2024-11-05".parse::<ProtocolVersion>().unwrap(),
47 ProtocolVersion::V20241105
48 );
49 assert_eq!(
50 "2025-03-26".parse::<ProtocolVersion>().unwrap(),
51 ProtocolVersion::V20250326
52 );
53
54 assert!("invalid".parse::<ProtocolVersion>().is_err());
56 }
57}