fix(transport-smtp): Use nom 4.0 to fix build errors in #298

This commit is contained in:
Jarred Nicholls
2018-06-18 14:14:21 -04:00
committed by Sameer
parent 60f06f1682
commit 6c3de0e85b
3 changed files with 10 additions and 12 deletions

View File

@@ -20,7 +20,7 @@ is-it-maintained-open-issues = { repository = "lettre/lettre" }
[dependencies] [dependencies]
log = "^0.4" log = "^0.4"
nom = { version = "^3.2", optional = true } nom = { version = "^4.0", optional = true }
bufstream = { version = "^0.1", optional = true } bufstream = { version = "^0.1", optional = true }
native-tls = { version = "^0.1", optional = true } native-tls = { version = "^0.1", optional = true }
base64 = { version = "^0.9", optional = true } base64 = { version = "^0.9", optional = true }

View File

@@ -37,7 +37,7 @@ pub enum Error {
/// TLS error /// TLS error
Tls(native_tls::Error), Tls(native_tls::Error),
/// Parsing error /// Parsing error
Parsing(nom::simple_errors::Err), Parsing(nom::ErrorKind),
} }
impl Display for Error { impl Display for Error {
@@ -77,7 +77,7 @@ impl StdError for Error {
Utf8Parsing(ref err) => Some(&*err), Utf8Parsing(ref err) => Some(&*err),
Io(ref err) => Some(&*err), Io(ref err) => Some(&*err),
Tls(ref err) => Some(&*err), Tls(ref err) => Some(&*err),
Parsing(ref err) => Some(&*err), Parsing(_) => None,
_ => None, _ => None,
} }
} }
@@ -95,8 +95,8 @@ impl From<native_tls::Error> for Error {
} }
} }
impl From<nom::simple_errors::Err> for Error { impl From<nom::ErrorKind> for Error {
fn from(err: nom::simple_errors::Err) -> Error { fn from(err: nom::ErrorKind) -> Error {
Parsing(err) Parsing(err)
} }
} }

View File

@@ -1,8 +1,7 @@
//! SMTP response, containing a mandatory return code and an optional text //! SMTP response, containing a mandatory return code and an optional text
//! message //! message
use nom::{crlf, ErrorKind as NomErrorKind, IResult as NomResult}; use nom::{crlf, ErrorKind as NomErrorKind};
use nom::simple_errors::Err as NomError;
use std::fmt::{Display, Formatter, Result}; use std::fmt::{Display, Formatter, Result};
use std::result; use std::result;
use std::str::{FromStr, from_utf8}; use std::str::{FromStr, from_utf8};
@@ -126,13 +125,12 @@ pub struct Response {
} }
impl FromStr for Response { impl FromStr for Response {
type Err = NomError; type Err = NomErrorKind;
fn from_str(s: &str) -> result::Result<Response, NomError> { fn from_str(s: &str) -> result::Result<Response, NomErrorKind> {
match parse_response(s.as_bytes()) { match parse_response(s.as_bytes()) {
NomResult::Done(_, res) => Ok(res), Ok((_, res)) => Ok(res),
NomResult::Error(e) => Err(e), Err(e) => Err(e.into_error_kind()),
NomResult::Incomplete(_) => Err(NomErrorKind::Complete),
} }
} }
} }