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

View file

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

View file

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