Properly implement the std::str::FromStr trait

This commit is contained in:
Rodolphe Breard 2019-01-06 16:37:07 +01:00
parent 4ed4609272
commit 074c3697d0
3 changed files with 11 additions and 4 deletions

View file

@ -1,6 +1,7 @@
use crate::errors::Error; use crate::errors::Error;
use nom::{alt, alt_complete, call, complete, cond, do_parse, error_position, map_res, named, opt, use nom::{alt, alt_complete, call, complete, cond, do_parse, error_position, map_res, named, opt,
tag, take_until, take_while}; tag, take_until, take_while};
use std::str::FromStr;
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum Kind { pub enum Kind {
@ -33,8 +34,10 @@ pub enum Event {
FilterResponse, FilterResponse,
} }
impl Event { impl FromStr for Event {
pub fn from_str(s: &str) -> Result<Event, Error> { type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let s = s.to_lowercase() let s = s.to_lowercase()
.replace("link", "link-") .replace("link", "link-")
.replace("tx", "tx-") .replace("tx", "tx-")
@ -69,8 +72,10 @@ pub struct Entry {
pub params: Option<String>, pub params: Option<String>,
} }
impl Entry { impl FromStr for Entry {
pub fn from_str(entry: &str) -> Result<Entry, Error> { type Err = Error;
fn from_str(entry: &str) -> Result<Self, Self::Err> {
let (_, res) = parse_entry(entry)?; let (_, res) = parse_entry(entry)?;
Ok(res) Ok(res)
} }

View file

@ -1,5 +1,6 @@
use crate::entry::{Entry, Event}; use crate::entry::{Entry, Event};
use crate::Response; use crate::Response;
use std::str::FromStr;
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum MatchEvent { pub enum MatchEvent {

View file

@ -5,6 +5,7 @@ mod event_handlers;
use log::{debug, error, warn}; use log::{debug, error, warn};
use std::collections::HashMap; use std::collections::HashMap;
use std::io; use std::io;
use std::str::FromStr;
use std::sync::mpsc; use std::sync::mpsc;
use std::thread; use std::thread;