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 pub fn route_key(self) -> &'static str {
24 match self {
25 IpFamily::V4 => "route:",
26 IpFamily::V6 => "route6:",
27 }
28 }
29
30 pub fn as_str(self) -> &'static str {
32 match self {
33 IpFamily::V4 => "IPv4",
34 IpFamily::V6 => "IPv6",
35 }
36 }
37}
38
39#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41pub enum OutputFormat {
42 Txt,
43 Nft,
44}
45
46impl FromStr for OutputFormat {
48 type Err = &'static str;
49
50 fn from_str(s: &str) -> Result<Self, Self::Err> {
51 match s.to_lowercase().as_str() {
52 "nft" => Ok(OutputFormat::Nft),
53 "txt" | "" => Ok(OutputFormat::Txt),
54 _ => Err("Invalid output format. Valid options: 'txt' or 'nft'"),
55 }
56 }
57}