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