Merge pull request #170 from amousset/try-macro
style(all): Replace try! by ?
This commit is contained in:
@@ -65,7 +65,7 @@ impl EmailTransport<FileResult> for FileEmailTransport {
|
||||
let mut file = self.path.clone();
|
||||
file.push(format!("{}.txt", email.message_id()));
|
||||
|
||||
let mut f = try!(File::create(file.as_path()));
|
||||
let mut f = File::create(file.as_path())?;
|
||||
|
||||
let simple_email = SimpleSendableEmail::new(
|
||||
email.from().clone(),
|
||||
@@ -74,9 +74,9 @@ impl EmailTransport<FileResult> for FileEmailTransport {
|
||||
email.message(),
|
||||
);
|
||||
|
||||
try!(f.write_all(
|
||||
f.write_all(
|
||||
serde_json::to_string(&simple_email)?.as_bytes(),
|
||||
));
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ impl EmailTransport<SendmailResult> for SendmailTransport {
|
||||
fn send<T: SendableEmail>(&mut self, email: T) -> SendmailResult {
|
||||
// Spawn the sendmail command
|
||||
let to_addresses: Vec<String> = email.to().iter().map(|x| x.to_string()).collect();
|
||||
let mut process = try!(
|
||||
let mut process =
|
||||
Command::new(&self.command)
|
||||
.args(
|
||||
&[
|
||||
@@ -59,7 +59,7 @@ impl EmailTransport<SendmailResult> for SendmailTransport {
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
);
|
||||
?;
|
||||
|
||||
match process.stdin.as_mut().unwrap().write_all(
|
||||
email.message().as_bytes(),
|
||||
|
||||
@@ -101,8 +101,8 @@ impl<S: Connector + Write + Read + Timeout + Debug> Client<S> {
|
||||
pub fn set_timeout(&mut self, duration: Option<Duration>) -> io::Result<()> {
|
||||
match self.stream {
|
||||
Some(ref mut stream) => {
|
||||
try!(stream.get_mut().set_read_timeout(duration));
|
||||
try!(stream.get_mut().set_read_timeout(duration));
|
||||
stream.get_mut().set_read_timeout(duration)?;
|
||||
stream.get_mut().set_read_timeout(duration)?;
|
||||
Ok(())
|
||||
}
|
||||
None => Ok(()),
|
||||
@@ -120,7 +120,7 @@ impl<S: Connector + Write + Read + Timeout + Debug> Client<S> {
|
||||
return_err!("The connection is already established", self);
|
||||
}
|
||||
|
||||
let mut addresses = try!(addr.to_socket_addrs());
|
||||
let mut addresses = addr.to_socket_addrs()?;
|
||||
|
||||
let server_addr = match addresses.next() {
|
||||
Some(addr) => addr,
|
||||
@@ -130,7 +130,7 @@ impl<S: Connector + Write + Read + Timeout + Debug> Client<S> {
|
||||
debug!("connecting to {}", server_addr);
|
||||
|
||||
// Try to connect
|
||||
self.set_stream(try!(Connector::connect(&server_addr, tls_connector)));
|
||||
self.set_stream(Connector::connect(&server_addr, tls_connector)?);
|
||||
|
||||
self.get_reply()
|
||||
}
|
||||
@@ -187,8 +187,8 @@ impl<S: Connector + Write + Read + Timeout + Debug> Client<S> {
|
||||
return Err(From::from("Connection closed"));
|
||||
}
|
||||
|
||||
try!(write!(self.stream.as_mut().unwrap(), "{}{}", string, end));
|
||||
try!(self.stream.as_mut().unwrap().flush());
|
||||
write!(self.stream.as_mut().unwrap(), "{}{}", string, end)?;
|
||||
self.stream.as_mut().unwrap().flush()?;
|
||||
|
||||
debug!("Wrote: {}", escape_crlf(string));
|
||||
|
||||
@@ -201,16 +201,16 @@ impl<S: Connector + Write + Read + Timeout + Debug> Client<S> {
|
||||
let mut parser = ResponseParser::default();
|
||||
|
||||
let mut line = String::new();
|
||||
try!(self.stream.as_mut().unwrap().read_line(&mut line));
|
||||
self.stream.as_mut().unwrap().read_line(&mut line)?;
|
||||
|
||||
debug!("Read: {}", escape_crlf(line.as_ref()));
|
||||
|
||||
while try!(parser.read_line(remove_crlf(line.as_ref()).as_ref())) {
|
||||
while parser.read_line(remove_crlf(line.as_ref()).as_ref())? {
|
||||
line.clear();
|
||||
try!(self.stream.as_mut().unwrap().read_line(&mut line));
|
||||
self.stream.as_mut().unwrap().read_line(&mut line)?;
|
||||
}
|
||||
|
||||
let response = try!(parser.response());
|
||||
let response = parser.response()?;
|
||||
|
||||
if response.is_positive() {
|
||||
Ok(response)
|
||||
|
||||
@@ -85,7 +85,7 @@ impl Connector for NetworkStream {
|
||||
addr: &SocketAddr,
|
||||
tls_connector: Option<&TlsConnector>,
|
||||
) -> io::Result<NetworkStream> {
|
||||
let tcp_stream = try!(TcpStream::connect(addr));
|
||||
let tcp_stream = TcpStream::connect(addr)?;
|
||||
|
||||
match tls_connector {
|
||||
Some(context) => {
|
||||
|
||||
@@ -203,7 +203,7 @@ pub struct SmtpTransportBuilder {
|
||||
impl SmtpTransportBuilder {
|
||||
/// Creates a new local SMTP client
|
||||
pub fn new<A: ToSocketAddrs>(addr: A) -> Result<SmtpTransportBuilder, Error> {
|
||||
let mut addresses = try!(addr.to_socket_addrs());
|
||||
let mut addresses = addr.to_socket_addrs()?;
|
||||
|
||||
match addresses.next() {
|
||||
Some(addr) => {
|
||||
@@ -407,20 +407,20 @@ impl EmailTransport<SmtpResult> for SmtpTransport {
|
||||
}
|
||||
|
||||
if self.state.connection_reuse_count == 0 {
|
||||
try!(self.client.connect(
|
||||
self.client.connect(
|
||||
&self.client_info.server_addr,
|
||||
match self.client_info.security_level {
|
||||
SecurityLevel::EncryptedWrapper => Some(&self.client_info.tls_connector),
|
||||
_ => None,
|
||||
},
|
||||
));
|
||||
)?;
|
||||
|
||||
try!(self.client.set_timeout(self.client_info.timeout));
|
||||
self.client.set_timeout(self.client_info.timeout)?;
|
||||
|
||||
// Log the connection
|
||||
info!("connection established to {}", self.client_info.server_addr);
|
||||
|
||||
try!(self.get_ehlo());
|
||||
self.get_ehlo()?;
|
||||
|
||||
match (
|
||||
&self.client_info.security_level,
|
||||
@@ -446,7 +446,7 @@ impl EmailTransport<SmtpResult> for SmtpTransport {
|
||||
debug!("connection encrypted");
|
||||
|
||||
// Send EHLO again
|
||||
try!(self.get_ehlo());
|
||||
self.get_ehlo()?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ impl ResponseParser {
|
||||
));
|
||||
}
|
||||
}
|
||||
None => self.code = Some(try!(line[0..3].parse::<Code>())),
|
||||
None => self.code = Some(line[0..3].parse::<Code>()?),
|
||||
}
|
||||
|
||||
if line.len() > 4 {
|
||||
|
||||
Reference in New Issue
Block a user