Fix Rust 2018 Idioms

This commit is contained in:
Paolo Barbolini
2020-10-10 12:18:15 +02:00
parent ed9ca92de8
commit 583df6af18
17 changed files with 55 additions and 50 deletions

View File

@@ -156,7 +156,7 @@ impl Address {
} }
impl Display for Address { impl Display for Address {
fn fmt(&self, f: &mut Formatter) -> FmtResult { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
f.write_str(&self.serialized) f.write_str(&self.serialized)
} }
} }
@@ -202,7 +202,7 @@ pub enum AddressError {
impl Error for AddressError {} impl Error for AddressError {}
impl Display for AddressError { impl Display for AddressError {
fn fmt(&self, f: &mut Formatter) -> FmtResult { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
match self { match self {
AddressError::MissingParts => f.write_str("Missing domain or user"), AddressError::MissingParts => f.write_str("Missing domain or user"),
AddressError::Unbalanced => f.write_str("Unbalanced angle bracket"), AddressError::Unbalanced => f.write_str("Unbalanced angle bracket"),
@@ -254,7 +254,7 @@ mod serde {
impl<'de> Visitor<'de> for FieldVisitor { impl<'de> Visitor<'de> for FieldVisitor {
type Value = Field; type Value = Field;
fn expecting(&self, formatter: &mut Formatter) -> FmtResult { fn expecting(&self, formatter: &mut Formatter<'_>) -> FmtResult {
formatter.write_str("'user' or 'domain'") formatter.write_str("'user' or 'domain'")
} }
@@ -279,7 +279,7 @@ mod serde {
impl<'de> Visitor<'de> for AddressVisitor { impl<'de> Visitor<'de> for AddressVisitor {
type Value = Address; type Value = Address;
fn expecting(&self, formatter: &mut Formatter) -> FmtResult { fn expecting(&self, formatter: &mut Formatter<'_>) -> FmtResult {
formatter.write_str("email address string or object") formatter.write_str("email address string or object")
} }

View File

@@ -27,13 +27,14 @@
#![doc(html_root_url = "https://docs.rs/crate/lettre/0.10.0-alpha.2")] #![doc(html_root_url = "https://docs.rs/crate/lettre/0.10.0-alpha.2")]
#![doc(html_favicon_url = "https://lettre.rs/favicon.ico")] #![doc(html_favicon_url = "https://lettre.rs/favicon.ico")]
#![doc(html_logo_url = "https://avatars0.githubusercontent.com/u/15113230?v=4")] #![doc(html_logo_url = "https://avatars0.githubusercontent.com/u/15113230?v=4")]
#![forbid(unsafe_code)]
#![deny( #![deny(
missing_copy_implementations, missing_copy_implementations,
trivial_casts, trivial_casts,
trivial_numeric_casts, trivial_numeric_casts,
unstable_features, unstable_features,
unused_import_braces, unused_import_braces,
unsafe_code rust_2018_idioms
)] )]
pub mod address; pub mod address;

View File

@@ -26,7 +26,7 @@ impl Default for ContentTransferEncoding {
} }
impl Display for ContentTransferEncoding { impl Display for ContentTransferEncoding {
fn fmt(&self, f: &mut FmtFormatter) -> FmtResult { fn fmt(&self, f: &mut FmtFormatter<'_>) -> FmtResult {
use self::ContentTransferEncoding::*; use self::ContentTransferEncoding::*;
f.write_str(match *self { f.write_str(match *self {
SevenBit => "7bit", SevenBit => "7bit",
@@ -73,7 +73,7 @@ impl Header for ContentTransferEncoding {
}) })
} }
fn fmt_header(&self, f: &mut HeaderFormatter) -> FmtResult { fn fmt_header(&self, f: &mut HeaderFormatter<'_, '_>) -> FmtResult {
f.fmt_line(&format!("{}", self)) f.fmt_line(&format!("{}", self))
} }
} }

View File

@@ -35,7 +35,7 @@ macro_rules! mailbox_header {
}).map($type_name) }).map($type_name)
} }
fn fmt_header(&self, f: &mut HeaderFormatter) -> FmtResult { fn fmt_header(&self, f: &mut HeaderFormatter<'_, '_>) -> FmtResult {
f.fmt_line(&self.0.recode_name(utf8_b::encode)) f.fmt_line(&self.0.recode_name(utf8_b::encode))
} }
} }
@@ -70,7 +70,7 @@ macro_rules! mailboxes_header {
.map($type_name) .map($type_name)
} }
fn fmt_header(&self, f: &mut HeaderFormatter) -> FmtResult { fn fmt_header(&self, f: &mut HeaderFormatter<'_, '_>) -> FmtResult {
format_mailboxes(self.0.iter(), f) format_mailboxes(self.0.iter(), f)
} }
} }
@@ -155,7 +155,7 @@ fn parse_mailboxes(raw: &[u8]) -> HyperResult<Mailboxes> {
Err(HeaderError::Header) Err(HeaderError::Header)
} }
fn format_mailboxes<'a>(mbs: Iter<'a, Mailbox>, f: &mut HeaderFormatter) -> FmtResult { fn format_mailboxes<'a>(mbs: Iter<'a, Mailbox>, f: &mut HeaderFormatter<'_, '_>) -> FmtResult {
f.fmt_line(&Mailboxes::from( f.fmt_line(&Mailboxes::from(
mbs.map(|mb| mb.recode_name(utf8_b::encode)) mbs.map(|mb| mb.recode_name(utf8_b::encode))
.collect::<Vec<_>>(), .collect::<Vec<_>>(),

View File

@@ -45,7 +45,7 @@ impl Header for MimeVersion {
}) })
} }
fn fmt_header(&self, f: &mut HeaderFormatter) -> FmtResult { fn fmt_header(&self, f: &mut HeaderFormatter<'_, '_>) -> FmtResult {
f.fmt_line(&format!("{}.{}", self.major, self.minor)) f.fmt_line(&format!("{}.{}", self.major, self.minor))
} }
} }

View File

@@ -26,7 +26,7 @@ macro_rules! text_header {
.map($type_name) .map($type_name)
} }
fn fmt_header(&self, f: &mut HeaderFormatter) -> FmtResult { fn fmt_header(&self, f: &mut HeaderFormatter<'_, '_>) -> FmtResult {
fmt_text(&self.0, f) fmt_text(&self.0, f)
} }
} }
@@ -50,7 +50,7 @@ fn parse_text(raw: &[u8]) -> HyperResult<String> {
Err(HeaderError::Header) Err(HeaderError::Header)
} }
fn fmt_text(s: &str, f: &mut HeaderFormatter) -> FmtResult { fn fmt_text(s: &str, f: &mut HeaderFormatter<'_, '_>) -> FmtResult {
f.fmt_line(&utf8_b::encode(s)) f.fmt_line(&utf8_b::encode(s))
} }

View File

@@ -37,7 +37,7 @@ impl<'de> Deserialize<'de> for Mailbox {
impl<'de> Visitor<'de> for FieldVisitor { impl<'de> Visitor<'de> for FieldVisitor {
type Value = Field; type Value = Field;
fn expecting(&self, formatter: &mut Formatter) -> FmtResult { fn expecting(&self, formatter: &mut Formatter<'_>) -> FmtResult {
formatter.write_str("'name' or 'email'") formatter.write_str("'name' or 'email'")
} }
@@ -62,7 +62,7 @@ impl<'de> Deserialize<'de> for Mailbox {
impl<'de> Visitor<'de> for MailboxVisitor { impl<'de> Visitor<'de> for MailboxVisitor {
type Value = Mailbox; type Value = Mailbox;
fn expecting(&self, formatter: &mut Formatter) -> FmtResult { fn expecting(&self, formatter: &mut Formatter<'_>) -> FmtResult {
formatter.write_str("mailbox string or object") formatter.write_str("mailbox string or object")
} }
@@ -123,7 +123,7 @@ impl<'de> Deserialize<'de> for Mailboxes {
impl<'de> Visitor<'de> for MailboxesVisitor { impl<'de> Visitor<'de> for MailboxesVisitor {
type Value = Mailboxes; type Value = Mailboxes;
fn expecting(&self, formatter: &mut Formatter) -> FmtResult { fn expecting(&self, formatter: &mut Formatter<'_>) -> FmtResult {
formatter.write_str("mailboxes string or sequence") formatter.write_str("mailboxes string or sequence")
} }

View File

@@ -65,7 +65,7 @@ impl Mailbox {
} }
impl Display for Mailbox { impl Display for Mailbox {
fn fmt(&self, f: &mut Formatter) -> FmtResult { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
if let Some(ref name) = self.name { if let Some(ref name) = self.name {
let name = name.trim(); let name = name.trim();
if !name.is_empty() { if !name.is_empty() {
@@ -218,7 +218,7 @@ impl Mailboxes {
/// ///
/// assert!(iter.next().is_none()); /// assert!(iter.next().is_none());
/// ``` /// ```
pub fn iter(&self) -> Iter<Mailbox> { pub fn iter(&self) -> Iter<'_, Mailbox> {
self.0.iter() self.0.iter()
} }
} }
@@ -271,7 +271,7 @@ impl Extend<Mailbox> for Mailboxes {
} }
impl Display for Mailboxes { impl Display for Mailboxes {
fn fmt(&self, f: &mut Formatter) -> FmtResult { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
let mut iter = self.iter(); let mut iter = self.iter();
if let Some(mbox) = iter.next() { if let Some(mbox) = iter.next() {

View File

@@ -19,7 +19,7 @@ pub enum Error {
} }
impl Display for Error { impl Display for Error {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> { fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), fmt::Error> {
match *self { match *self {
Client(err) => fmt.write_str(err), Client(err) => fmt.write_str(err),
Io(ref err) => err.fmt(fmt), Io(ref err) => err.fmt(fmt),

View File

@@ -20,7 +20,7 @@ pub enum Error {
} }
impl Display for Error { impl Display for Error {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> { fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), fmt::Error> {
match *self { match *self {
Client(ref err) => err.fmt(fmt), Client(ref err) => err.fmt(fmt),
Utf8Parsing(ref err) => err.fmt(fmt), Utf8Parsing(ref err) => err.fmt(fmt),

View File

@@ -52,7 +52,7 @@ pub enum Mechanism {
} }
impl Display for Mechanism { impl Display for Mechanism {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str(match *self { f.write_str(match *self {
Mechanism::Plain => "PLAIN", Mechanism::Plain => "PLAIN",
Mechanism::Login => "LOGIN", Mechanism::Login => "LOGIN",

View File

@@ -189,7 +189,7 @@ impl AsyncNetworkStream {
impl futures_io::AsyncRead for AsyncNetworkStream { impl futures_io::AsyncRead for AsyncNetworkStream {
fn poll_read( fn poll_read(
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
cx: &mut Context, cx: &mut Context<'_>,
buf: &mut [u8], buf: &mut [u8],
) -> Poll<IoResult<usize>> { ) -> Poll<IoResult<usize>> {
match self.inner { match self.inner {
@@ -208,7 +208,11 @@ impl futures_io::AsyncRead for AsyncNetworkStream {
} }
impl futures_io::AsyncWrite for AsyncNetworkStream { impl futures_io::AsyncWrite for AsyncNetworkStream {
fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context, buf: &[u8]) -> Poll<IoResult<usize>> { fn poll_write(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<IoResult<usize>> {
match self.inner { match self.inner {
#[cfg(feature = "tokio02")] #[cfg(feature = "tokio02")]
InnerAsyncNetworkStream::Tokio02Tcp(ref mut s) => Pin::new(s).poll_write(cx, buf), InnerAsyncNetworkStream::Tokio02Tcp(ref mut s) => Pin::new(s).poll_write(cx, buf),
@@ -223,7 +227,7 @@ impl futures_io::AsyncWrite for AsyncNetworkStream {
} }
} }
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<IoResult<()>> { fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<IoResult<()>> {
match self.inner { match self.inner {
#[cfg(feature = "tokio02")] #[cfg(feature = "tokio02")]
InnerAsyncNetworkStream::Tokio02Tcp(ref mut s) => Pin::new(s).poll_flush(cx), InnerAsyncNetworkStream::Tokio02Tcp(ref mut s) => Pin::new(s).poll_flush(cx),
@@ -238,7 +242,7 @@ impl futures_io::AsyncWrite for AsyncNetworkStream {
} }
} }
fn poll_close(self: Pin<&mut Self>, _cx: &mut Context) -> Poll<IoResult<()>> { fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<IoResult<()>> {
Poll::Ready(self.shutdown(Shutdown::Write)) Poll::Ready(self.shutdown(Shutdown::Write))
} }
} }

View File

@@ -19,7 +19,7 @@ pub struct Ehlo {
} }
impl Display for Ehlo { impl Display for Ehlo {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "EHLO {}\r\n", self.client_id) write!(f, "EHLO {}\r\n", self.client_id)
} }
} }
@@ -37,7 +37,7 @@ impl Ehlo {
pub struct Starttls; pub struct Starttls;
impl Display for Starttls { impl Display for Starttls {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("STARTTLS\r\n") f.write_str("STARTTLS\r\n")
} }
} }
@@ -51,7 +51,7 @@ pub struct Mail {
} }
impl Display for Mail { impl Display for Mail {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!( write!(
f, f,
"MAIL FROM:<{}>", "MAIL FROM:<{}>",
@@ -80,7 +80,7 @@ pub struct Rcpt {
} }
impl Display for Rcpt { impl Display for Rcpt {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "RCPT TO:<{}>", self.recipient)?; write!(f, "RCPT TO:<{}>", self.recipient)?;
for parameter in &self.parameters { for parameter in &self.parameters {
write!(f, " {}", parameter)?; write!(f, " {}", parameter)?;
@@ -105,7 +105,7 @@ impl Rcpt {
pub struct Data; pub struct Data;
impl Display for Data { impl Display for Data {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("DATA\r\n") f.write_str("DATA\r\n")
} }
} }
@@ -116,7 +116,7 @@ impl Display for Data {
pub struct Quit; pub struct Quit;
impl Display for Quit { impl Display for Quit {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("QUIT\r\n") f.write_str("QUIT\r\n")
} }
} }
@@ -127,7 +127,7 @@ impl Display for Quit {
pub struct Noop; pub struct Noop;
impl Display for Noop { impl Display for Noop {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("NOOP\r\n") f.write_str("NOOP\r\n")
} }
} }
@@ -140,7 +140,7 @@ pub struct Help {
} }
impl Display for Help { impl Display for Help {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("HELP")?; f.write_str("HELP")?;
if let Some(argument) = &self.argument { if let Some(argument) = &self.argument {
write!(f, " {}", argument)?; write!(f, " {}", argument)?;
@@ -164,7 +164,7 @@ pub struct Vrfy {
} }
impl Display for Vrfy { impl Display for Vrfy {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "VRFY {}\r\n", self.argument) write!(f, "VRFY {}\r\n", self.argument)
} }
} }
@@ -184,7 +184,7 @@ pub struct Expn {
} }
impl Display for Expn { impl Display for Expn {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "EXPN {}\r\n", self.argument) write!(f, "EXPN {}\r\n", self.argument)
} }
} }
@@ -202,7 +202,7 @@ impl Expn {
pub struct Rset; pub struct Rset;
impl Display for Rset { impl Display for Rset {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("RSET\r\n") f.write_str("RSET\r\n")
} }
} }
@@ -218,7 +218,7 @@ pub struct Auth {
} }
impl Display for Auth { impl Display for Auth {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let encoded_response = self.response.as_ref().map(base64::encode); let encoded_response = self.response.as_ref().map(base64::encode);
if self.mechanism.supports_initial_response() { if self.mechanism.supports_initial_response() {

View File

@@ -48,7 +48,7 @@ pub enum Error {
} }
impl Display for Error { impl Display for Error {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> { fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), fmt::Error> {
match *self { match *self {
// Try to display the first line of the server's response that usually // Try to display the first line of the server's response that usually
// contains a short humanly readable error message // contains a short humanly readable error message

View File

@@ -48,7 +48,7 @@ impl Default for ClientId {
} }
impl Display for ClientId { impl Display for ClientId {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match *self { match *self {
Self::Domain(ref value) => f.write_str(value), Self::Domain(ref value) => f.write_str(value),
Self::Ipv4(ref value) => write!(f, "[{}]", value), Self::Ipv4(ref value) => write!(f, "[{}]", value),
@@ -86,7 +86,7 @@ pub enum Extension {
} }
impl Display for Extension { impl Display for Extension {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match *self { match *self {
Extension::EightBitMime => f.write_str("8BITMIME"), Extension::EightBitMime => f.write_str("8BITMIME"),
Extension::SmtpUtfEight => f.write_str("SMTPUTF8"), Extension::SmtpUtfEight => f.write_str("SMTPUTF8"),
@@ -111,7 +111,7 @@ pub struct ServerInfo {
} }
impl Display for ServerInfo { impl Display for ServerInfo {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let features = if self.features.is_empty() { let features = if self.features.is_empty() {
"no supported features".to_string() "no supported features".to_string()
} else { } else {
@@ -215,7 +215,7 @@ pub enum MailParameter {
} }
impl Display for MailParameter { impl Display for MailParameter {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match *self { match *self {
MailParameter::Body(ref value) => write!(f, "BODY={}", value), MailParameter::Body(ref value) => write!(f, "BODY={}", value),
MailParameter::Size(size) => write!(f, "SIZE={}", size), MailParameter::Size(size) => write!(f, "SIZE={}", size),
@@ -243,7 +243,7 @@ pub enum MailBodyParameter {
} }
impl Display for MailBodyParameter { impl Display for MailBodyParameter {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match *self { match *self {
MailBodyParameter::SevenBit => f.write_str("7BIT"), MailBodyParameter::SevenBit => f.write_str("7BIT"),
MailBodyParameter::EightBitMime => f.write_str("8BITMIME"), MailBodyParameter::EightBitMime => f.write_str("8BITMIME"),
@@ -265,7 +265,7 @@ pub enum RcptParameter {
} }
impl Display for RcptParameter { impl Display for RcptParameter {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match *self { match *self {
RcptParameter::Other { RcptParameter::Other {
ref keyword, ref keyword,

View File

@@ -32,7 +32,7 @@ pub enum Severity {
} }
impl Display for Severity { impl Display for Severity {
fn fmt(&self, f: &mut Formatter) -> Result { fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "{}", *self as u8) write!(f, "{}", *self as u8)
} }
} }
@@ -56,7 +56,7 @@ pub enum Category {
} }
impl Display for Category { impl Display for Category {
fn fmt(&self, f: &mut Formatter) -> Result { fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "{}", *self as u8) write!(f, "{}", *self as u8)
} }
} }
@@ -88,7 +88,7 @@ pub enum Detail {
} }
impl Display for Detail { impl Display for Detail {
fn fmt(&self, f: &mut Formatter) -> Result { fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "{}", *self as u8) write!(f, "{}", *self as u8)
} }
} }
@@ -106,7 +106,7 @@ pub struct Code {
} }
impl Display for Code { impl Display for Code {
fn fmt(&self, f: &mut Formatter) -> Result { fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "{}{}{}", self.severity, self.category, self.detail) write!(f, "{}{}{}", self.severity, self.category, self.detail)
} }
} }

View File

@@ -8,7 +8,7 @@ use std::fmt::{Display, Formatter, Result as FmtResult};
pub struct XText<'a>(pub &'a str); pub struct XText<'a>(pub &'a str);
impl<'a> Display for XText<'a> { impl<'a> Display for XText<'a> {
fn fmt(&self, f: &mut Formatter) -> FmtResult { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
let mut rest = self.0; let mut rest = self.0;
while let Some(idx) = rest.find(|c| c < '!' || c == '+' || c == '=') { while let Some(idx) = rest.find(|c| c < '!' || c == '+' || c == '=') {
let (start, end) = rest.split_at(idx); let (start, end) = rest.split_at(idx);