From 7f9b2c515014367b8b4c82b95c8fc83fd21f6954 Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Sat, 4 Apr 2015 22:34:01 +0200 Subject: [PATCH] Fix for latest nightly --- Cargo.toml | 2 +- src/client/authentication.rs | 4 ++-- src/client/mod.rs | 29 ++++++++++++++--------------- src/error.rs | 15 +++++++-------- src/lib.rs | 4 ++-- src/mailer/header.rs | 2 +- src/response.rs | 4 ++-- src/sender/mod.rs | 8 ++++---- 8 files changed, 33 insertions(+), 35 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5d0b055..e86bad8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "smtp" -version = "0.0.9" +version = "0.0.10" description = "Simple SMTP client" readme = "README.md" documentation = "http://amousset.github.io/rust-smtp/smtp/" diff --git a/src/client/authentication.rs b/src/client/authentication.rs index 913b008..4984596 100644 --- a/src/client/authentication.rs +++ b/src/client/authentication.rs @@ -39,13 +39,13 @@ mod test { #[test] fn test_plain() { - assert_eq!(plain("username", "password").as_slice(), "AHVzZXJuYW1lAHBhc3N3b3Jk"); + assert_eq!(plain("username", "password"), "AHVzZXJuYW1lAHBhc3N3b3Jk"); } #[test] fn test_cram_md5() { assert_eq!(cram_md5("alice", "wonderland", - "PDE3ODkzLjEzMjA2NzkxMjNAdGVzc2VyYWN0LnN1c2FtLmluPg==").as_slice(), + "PDE3ODkzLjEzMjA2NzkxMjNAdGVzc2VyYWN0LnN1c2FtLmluPg=="), "YWxpY2UgNjRiMmE0M2MxZjZlZDY4MDZhOTgwOTE0ZTIzZTc1ZjA="); } } diff --git a/src/client/mod.rs b/src/client/mod.rs index 2c1a401..befa765 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -10,7 +10,6 @@ //! SMTP client use std::string::String; -use std::error::FromError; use std::net::TcpStream; use std::net::{SocketAddr, ToSocketAddrs}; use std::io::{BufRead, BufStream, Read, Write}; @@ -44,7 +43,7 @@ fn escape_crlf(string: &str) -> String { } /// Structure that implements the SMTP client -pub struct Client { +pub struct Client { /// TCP stream between client and server /// Value is None before connection stream: Option>, @@ -55,11 +54,11 @@ pub struct Client { macro_rules! return_err ( ($err: expr, $client: ident) => ({ - return Err(FromError::from_error($err)) + return Err(From::from($err)) }) ); -impl Client { +impl Client { /// Creates a new SMTP client /// /// It does not connects to the server, but only creates the `Client` @@ -180,7 +179,7 @@ impl Client { /// Sends a string to the server and gets the response fn send_server(&mut self, string: &str, end: &str) -> SmtpResult { if self.stream.is_none() { - return Err(FromError::from_error("Connection closed")); + return Err(From::from("Connection closed")); } try!(write!(self.stream.as_mut().unwrap(), "{}{}", string, end)); @@ -198,12 +197,12 @@ impl Client { // If the string is too short to be a response code if line.len() < 3 { - return Err(FromError::from_error("Could not parse reply code, line too short")); + return Err(From::from("Could not parse reply code, line too short")); } let (severity, category, detail) = match (line[0..1].parse::(), line[1..2].parse::(), line[2..3].parse::()) { (Ok(severity), Ok(category), Ok(detail)) => (severity, category, detail), - _ => return Err(FromError::from_error("Could not parse reply code")), + _ => return Err(From::from("Could not parse reply code")), }; let mut message = Vec::new(); @@ -224,7 +223,7 @@ impl Client { match response.is_positive() { true => Ok(response), - false => Err(FromError::from_error(response)), + false => Err(From::from(response)), } } } @@ -235,18 +234,18 @@ mod test { #[test] fn test_escape_dot() { - assert_eq!(escape_dot(".test").as_slice(), "..test"); - assert_eq!(escape_dot("\r.\n.\r\n").as_slice(), "\r..\n..\r\n"); - assert_eq!(escape_dot("test\r\n.test\r\n").as_slice(), "test\r\n..test\r\n"); - assert_eq!(escape_dot("test\r\n.\r\ntest").as_slice(), "test\r\n..\r\ntest"); + assert_eq!(escape_dot(".test"), "..test"); + assert_eq!(escape_dot("\r.\n.\r\n"), "\r..\n..\r\n"); + assert_eq!(escape_dot("test\r\n.test\r\n"), "test\r\n..test\r\n"); + assert_eq!(escape_dot("test\r\n.\r\ntest"), "test\r\n..\r\ntest"); } #[test] fn test_escape_crlf() { - assert_eq!(escape_crlf("\r\n").as_slice(), ""); - assert_eq!(escape_crlf("EHLO my_name\r\n").as_slice(), "EHLO my_name"); + assert_eq!(escape_crlf("\r\n"), ""); + assert_eq!(escape_crlf("EHLO my_name\r\n"), "EHLO my_name"); assert_eq!( - escape_crlf("EHLO my_name\r\nSIZE 42\r\n").as_slice(), + escape_crlf("EHLO my_name\r\nSIZE 42\r\n"), "EHLO my_nameSIZE 42" ); } diff --git a/src/error.rs b/src/error.rs index ff935d8..9b84e5b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -11,7 +11,6 @@ use std::error::Error; use std::io; -use std::error::FromError; use std::fmt::{Display, Formatter}; use std::fmt; @@ -19,7 +18,7 @@ use response::{Severity, Response}; use self::SmtpError::*; /// An enum of all error kinds. -#[derive(PartialEq, Eq, Clone, Debug)] +#[derive(Debug)] pub enum SmtpError { /// Transient error, 4xx reply code /// @@ -59,14 +58,14 @@ impl Error for SmtpError { } } -impl FromError for SmtpError { - fn from_error(err: io::Error) -> SmtpError { +impl From for SmtpError { + fn from(err: io::Error) -> SmtpError { IoError(err) } } -impl FromError for SmtpError { - fn from_error(response: Response) -> SmtpError { +impl From for SmtpError { + fn from(response: Response) -> SmtpError { match response.severity() { Severity::TransientNegativeCompletion => TransientError(response), Severity::PermanentNegativeCompletion => PermanentError(response), @@ -75,8 +74,8 @@ impl FromError for SmtpError { } } -impl FromError<&'static str> for SmtpError { - fn from_error(string: &'static str) -> SmtpError { +impl From<&'static str> for SmtpError { + fn from(string: &'static str) -> SmtpError { ClientError(string.to_string()) } } diff --git a/src/lib.rs b/src/lib.rs index 9c71731..167cea1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -140,11 +140,11 @@ //! let _ = email_client.quit(); //! ``` -#![feature(plugin, core, collections, str_words)] +#![feature(plugin, collections, str_words, slice_patterns)] #![deny(missing_docs)] #[macro_use] extern crate log; -extern crate "rustc-serialize" as serialize; +extern crate rustc_serialize as serialize; extern crate crypto; extern crate time; extern crate uuid; diff --git a/src/mailer/header.rs b/src/mailer/header.rs index 1246a4b..ab8e2b6 100644 --- a/src/mailer/header.rs +++ b/src/mailer/header.rs @@ -76,7 +76,7 @@ impl Display for Header { Header::MimeVersion => "MIME-Version", Header::ContentType(_) => "Content-Type", Header::MessageId(_) => "Message-Id", - Header::Other(ref name, _) => name.as_slice(), + Header::Other(ref name, _) => name.as_ref(), }, COLON, SP, match *self { diff --git a/src/response.rs b/src/response.rs index d25883a..e3b3098 100644 --- a/src/response.rs +++ b/src/response.rs @@ -208,7 +208,7 @@ mod test { #[test] fn test_severity_fmt() { - assert_eq!(format!("{}", Severity::PositiveCompletion).as_slice(), "2"); + assert_eq!(format!("{}", Severity::PositiveCompletion), "2"); } #[test] @@ -220,7 +220,7 @@ mod test { #[test] fn test_category_fmt() { - assert_eq!(format!("{}", Category::Unspecified4).as_slice(), "4"); + assert_eq!(format!("{}", Category::Unspecified4), "4"); } #[test] diff --git a/src/sender/mod.rs b/src/sender/mod.rs index 4f14d90..558a4c0 100644 --- a/src/sender/mod.rs +++ b/src/sender/mod.rs @@ -102,7 +102,7 @@ struct State { } /// Structure that implements the high level SMTP client -pub struct Sender { +pub struct Sender { /// Information about the server /// Value is None before HELO/EHLO server_info: Option, @@ -129,7 +129,7 @@ macro_rules! try_smtp ( }) ); -impl Sender { +impl Sender { /// Creates a new SMTP client /// /// It does not connects to the server, but only creates the `Sender` @@ -265,8 +265,8 @@ impl Sender { // Log the message info!("{}: conn_use={}, size={}, status=sent ({})", current_message, - self.state.connection_reuse_count, message.len(), match result.as_ref().ok().unwrap().message().as_slice() { - [ref line, ..] => line.as_slice(), + self.state.connection_reuse_count, message.len(), match result.as_ref().ok().unwrap().message().as_ref() { + [ref line, ..] => line.as_ref(), [] => "no response", } );