diff options
Diffstat (limited to 'src/configuration/uapi/set.rs')
-rw-r--r-- | src/configuration/uapi/set.rs | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/src/configuration/uapi/set.rs b/src/configuration/uapi/set.rs index 575c7ad..c609d83 100644 --- a/src/configuration/uapi/set.rs +++ b/src/configuration/uapi/set.rs @@ -7,8 +7,8 @@ use super::{ConfigError, Configuration}; #[derive(Copy, Clone)] enum ParserState { Peer { - public_key: PublicKey, // peer identity - update_only: bool, // is the update_only flag set + public_key: PublicKey, + update_only: bool, }, Interface, } @@ -18,10 +18,6 @@ struct LineParser<C: Configuration> { state: ParserState, } -struct Serializer<C: Configuration> { - config: C, -} - impl<C: Configuration> LineParser<C> { fn new_peer(value: &str) -> Result<ParserState, ConfigError> { match <[u8; 32]>::from_hex(value) { @@ -34,6 +30,7 @@ impl<C: Configuration> LineParser<C> { } fn parse_line(&mut self, key: &str, value: &str) -> Option<ConfigError> { + // add the peer if not update_only let flush_peer = |st: ParserState| -> ParserState { match st { ParserState::Peer { @@ -51,7 +48,7 @@ impl<C: Configuration> LineParser<C> { }; // parse line and update parser state - let new_state = match self.state { + match self.state { // configure the interface ParserState::Interface => match key { // opt: set private key @@ -202,14 +199,8 @@ impl<C: Configuration> LineParser<C> { // unknown key _ => Err(ConfigError::InvalidKey), }, - }; - - match new_state { - Err(e) => Some(e), - Ok(st) => { - self.state = st; - None - } } + .map(|st| self.state = st) + .err() } } |