Skip to content

Commit 7342557

Browse files
committed
impl FromStr for NeighbourState
1 parent 6dd74c9 commit 7342557

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/neighbour/state.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,26 @@ impl std::fmt::Display for NeighbourState {
7676
}
7777
}
7878
}
79+
80+
pub struct NeighbourStateParseError;
81+
82+
impl std::str::FromStr for NeighbourState {
83+
type Err = NeighbourStateParseError;
84+
85+
fn from_str(state: &str) -> Result<Self, Self::Err> {
86+
let state = match state {
87+
"incomplete" => Self::Incomplete,
88+
"reachable" => Self::Reachable,
89+
"stale" => Self::Stale,
90+
"delay" => Self::Delay,
91+
"probe" => Self::Probe,
92+
"failed" => Self::Failed,
93+
"noarp" => Self::Noarp,
94+
"permanent" => Self::Permanent,
95+
"none" => Self::None,
96+
_ => return Err(NeighbourStateParseError),
97+
};
98+
99+
Ok(state)
100+
}
101+
}

0 commit comments

Comments
 (0)