fire_scope/
common.rs

1use std::str::FromStr;
2
3#[derive(Debug, Clone, Copy)]
4pub enum IpFamily {
5    V4,
6    V6,
7}
8
9impl FromStr for IpFamily {
10    type Err = &'static str;
11
12    fn from_str(s: &str) -> Result<Self, Self::Err> {
13        match s {
14            "IPv4" => Ok(IpFamily::V4),
15            "IPv6" => Ok(IpFamily::V6),
16            _ => Err("Invalid IP version. Must be 'IPv4' or 'IPv6'"),
17        }
18    }
19}
20
21impl IpFamily {
22    /// whois の route キーを返すメソッド
23    pub fn route_key(self) -> &'static str {
24        match self {
25            IpFamily::V4 => "route:",
26            IpFamily::V6 => "route6:",
27        }
28    }
29
30    /// ログ表示などに使う文字列
31    pub fn as_str(self) -> &'static str {
32        match self {
33            IpFamily::V4 => "IPv4",
34            IpFamily::V6 => "IPv6",
35        }
36    }
37}