diff --git a/opensmtpd/src/entry.rs b/opensmtpd/src/entry.rs index 4b5489e..6bc10cb 100644 --- a/opensmtpd/src/entry.rs +++ b/opensmtpd/src/entry.rs @@ -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 { +impl FromStr for Event { + type Err = Error; + + fn from_str(s: &str) -> Result { let s = s.to_lowercase() .replace("link", "link-") .replace("tx", "tx-") @@ -69,8 +72,10 @@ pub struct Entry { pub params: Option, } -impl Entry { - pub fn from_str(entry: &str) -> Result { +impl FromStr for Entry { + type Err = Error; + + fn from_str(entry: &str) -> Result { let (_, res) = parse_entry(entry)?; Ok(res) } diff --git a/opensmtpd/src/event_handlers.rs b/opensmtpd/src/event_handlers.rs index 8e54d5f..d42a9f9 100644 --- a/opensmtpd/src/event_handlers.rs +++ b/opensmtpd/src/event_handlers.rs @@ -1,5 +1,6 @@ use crate::entry::{Entry, Event}; use crate::Response; +use std::str::FromStr; #[derive(Clone, Debug, PartialEq)] pub enum MatchEvent { diff --git a/opensmtpd/src/lib.rs b/opensmtpd/src/lib.rs index 9d59d7d..c520ba0 100644 --- a/opensmtpd/src/lib.rs +++ b/opensmtpd/src/lib.rs @@ -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;