Skip to content

Commit

Permalink
fix(all): fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini committed Feb 17, 2020
1 parent a440ae5 commit 50ab324
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 47 deletions.
17 changes: 6 additions & 11 deletions src/file/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Error and result type for file transport

use self::Error::*;
use serde_json;
use std::io;
use std::{
error::Error as StdError,
Expand All @@ -20,20 +19,16 @@ pub enum Error {
}

impl Display for Error {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {
fmt.write_str(self.description())
}
}

impl StdError for Error {
fn description(&self) -> &str {
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
match *self {
Client(err) => err,
Io(ref err) => err.description(),
JsonSerialization(ref err) => err.description(),
Client(err) => write!(f, "{}", err),
Io(ref err) => write!(f, "{}", err),
JsonSerialization(ref err) => write!(f, "{}", err),
}
}
}

impl StdError for Error {
fn cause(&self) -> Option<&dyn StdError> {
match *self {
Io(ref err) => Some(&*err),
Expand Down
1 change: 0 additions & 1 deletion src/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::file::error::FileResult;
use crate::Email;
use crate::Envelope;
use crate::Transport;
use serde_json;
use std::fs::File;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
Expand Down
16 changes: 6 additions & 10 deletions src/sendmail/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,16 @@ pub enum Error {
}

impl Display for Error {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {
fmt.write_str(self.description())
}
}

impl StdError for Error {
fn description(&self) -> &str {
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
match *self {
Client(ref err) => err,
Utf8Parsing(ref err) => err.description(),
Io(ref err) => err.description(),
Client(ref err) => write!(f, "{}", err),
Utf8Parsing(ref err) => write!(f, "{}", err),
Io(ref err) => write!(f, "{}", err),
}
}
}

impl StdError for Error {
fn cause(&self) -> Option<&dyn StdError> {
match *self {
Io(ref err) => Some(&*err),
Expand Down
3 changes: 1 addition & 2 deletions src/smtp/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::smtp::extension::ClientId;
use crate::smtp::extension::{MailParameter, RcptParameter};
use crate::smtp::response::Response;
use crate::EmailAddress;
use base64;
use log::debug;
use std::convert::AsRef;
use std::fmt::{self, Display, Formatter};
Expand Down Expand Up @@ -247,7 +246,7 @@ impl AuthCommand {
challenge: Option<String>,
) -> Result<AuthCommand, Error> {
let response = if mechanism.supports_initial_response() || challenge.is_some() {
Some(mechanism.response(&credentials, challenge.as_ref().map(String::as_str))?)
Some(mechanism.response(&credentials, challenge.as_deref())?)
} else {
None
};
Expand Down
39 changes: 16 additions & 23 deletions src/smtp/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use self::Error::*;
use crate::smtp::response::{Response, Severity};
use base64::DecodeError;
#[cfg(feature = "native-tls")]
use native_tls;
use nom;
use std::error::Error as StdError;
use std::fmt;
use std::fmt::{Display, Formatter};
Expand Down Expand Up @@ -46,39 +44,34 @@ pub enum Error {
}

impl Display for Error {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {
fmt.write_str(self.description())
}
}

impl StdError for Error {
#[cfg_attr(feature = "cargo-clippy", allow(clippy::match_same_arms))]
fn description(&self) -> &str {
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
match *self {
// Try to display the first line of the server's response that usually
// contains a short humanly readable error message
Transient(ref err) => match err.first_line() {
Some(line) => line,
None => "undetailed transient error during SMTP transaction",
Some(line) => write!(f, "{}", line),
None => write!(f, "undetailed transient error during SMTP transaction"),
},
Permanent(ref err) => match err.first_line() {
Some(line) => line,
None => "undetailed permanent error during SMTP transaction",
Some(line) => write!(f, "{}", line),
None => write!(f, "undetailed permanent error during SMTP transaction"),
},
ResponseParsing(err) => err,
ChallengeParsing(ref err) => err.description(),
Utf8Parsing(ref err) => err.description(),
Resolution => "could not resolve hostname",
Client(err) => err,
Io(ref err) => err.description(),
ResponseParsing(err) => write!(f, "{}", err),
ChallengeParsing(ref err) => write!(f, "{}", err),
Utf8Parsing(ref err) => write!(f, "{}", err),
Resolution => write!(f, "could not resolve hostname"),
Client(err) => write!(f, "{}", err),
Io(ref err) => write!(f, "{}", err),
#[cfg(feature = "native-tls")]
Tls(ref err) => err.description(),
Parsing(ref err) => err.description(),
Tls(ref err) => write!(f, "{}", err),
Parsing(ref err) => write!(f, "{}", err.description()),
#[cfg(feature = "rustls-tls")]
InvalidDNSName(ref err) => err.description(),
InvalidDNSName(ref err) => write!(f, "{}", err),
}
}
}

impl StdError for Error {
fn cause(&self) -> Option<&dyn StdError> {
match *self {
ChallengeParsing(ref err) => Some(&*err),
Expand Down

0 comments on commit 50ab324

Please sign in to comment.