We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6dd74c9 commit ef90458Copy full SHA for ef90458
1 file changed
src/neighbour/state.rs
@@ -76,3 +76,35 @@ impl std::fmt::Display for NeighbourState {
76
}
77
78
79
+
80
+impl std::str::FromStr for NeighbourState {
81
+ type Err = NeighbourStateParseError;
82
83
+ fn from_str(state: &str) -> Result<Self, Self::Err> {
84
+ let state = match state {
85
+ "incomplete" => Self::Incomplete,
86
+ "reachable" => Self::Reachable,
87
+ "stale" => Self::Stale,
88
+ "delay" => Self::Delay,
89
+ "probe" => Self::Probe,
90
+ "failed" => Self::Failed,
91
+ "noarp" => Self::Noarp,
92
+ "permanent" => Self::Permanent,
93
+ "none" => Self::None,
94
+ _ => return Err(NeighbourStateParseError),
95
+ };
96
97
+ Ok(state)
98
+ }
99
+}
100
101
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
102
+pub struct NeighbourStateParseError;
103
104
+impl std::fmt::Display for NeighbourStateParseError {
105
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
106
+ write!(f, "invalid neighbour state")
107
108
109
110
+impl std::error::Error for NeighbourStateParseError {}
0 commit comments