Fix for latest nightly

This commit is contained in:
Alexis Mousset
2015-04-04 22:34:01 +02:00
parent 654fb6fadc
commit 7f9b2c5150
8 changed files with 33 additions and 35 deletions

View File

@@ -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/"

View File

@@ -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=");
}
}

View File

@@ -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<S = TcpStream> {
pub struct Client<S: Write + Read = TcpStream> {
/// TCP stream between client and server
/// Value is None before connection
stream: Option<BufStream<S>>,
@@ -55,11 +54,11 @@ pub struct Client<S = TcpStream> {
macro_rules! return_err (
($err: expr, $client: ident) => ({
return Err(FromError::from_error($err))
return Err(From::from($err))
})
);
impl<S = TcpStream> Client<S> {
impl<S: Write + Read = TcpStream> Client<S> {
/// Creates a new SMTP client
///
/// It does not connects to the server, but only creates the `Client`
@@ -180,7 +179,7 @@ impl<S: Connecter + Write + Read = TcpStream> Client<S> {
/// 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<S: Connecter + Write + Read = TcpStream> Client<S> {
// 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::<Severity>(), line[1..2].parse::<Category>(), line[2..3].parse::<u8>()) {
(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<S: Connecter + Write + Read = TcpStream> Client<S> {
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(), "<CR><LF>");
assert_eq!(escape_crlf("EHLO my_name\r\n").as_slice(), "EHLO my_name<CR><LF>");
assert_eq!(escape_crlf("\r\n"), "<CR><LF>");
assert_eq!(escape_crlf("EHLO my_name\r\n"), "EHLO my_name<CR><LF>");
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_name<CR><LF>SIZE 42<CR><LF>"
);
}

View File

@@ -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<io::Error> for SmtpError {
fn from_error(err: io::Error) -> SmtpError {
impl From<io::Error> for SmtpError {
fn from(err: io::Error) -> SmtpError {
IoError(err)
}
}
impl FromError<Response> for SmtpError {
fn from_error(response: Response) -> SmtpError {
impl From<Response> for SmtpError {
fn from(response: Response) -> SmtpError {
match response.severity() {
Severity::TransientNegativeCompletion => TransientError(response),
Severity::PermanentNegativeCompletion => PermanentError(response),
@@ -75,8 +74,8 @@ impl FromError<Response> 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())
}
}

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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]

View File

@@ -102,7 +102,7 @@ struct State {
}
/// Structure that implements the high level SMTP client
pub struct Sender<S = TcpStream> {
pub struct Sender<S: Write + Read = TcpStream> {
/// Information about the server
/// Value is None before HELO/EHLO
server_info: Option<ServerInfo>,
@@ -129,7 +129,7 @@ macro_rules! try_smtp (
})
);
impl<S = TcpStream> Sender<S> {
impl<S: Write + Read = TcpStream> Sender<S> {
/// Creates a new SMTP client
///
/// It does not connects to the server, but only creates the `Sender`
@@ -265,8 +265,8 @@ impl<S: Connecter + Write + Read = TcpStream> Sender<S> {
// 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",
}
);