replace try! with ? syntax

This commit is contained in:
Astro 2018-08-02 20:10:26 +02:00
parent b929a3c71e
commit b82237f422
4 changed files with 8 additions and 12 deletions

View file

@ -60,7 +60,7 @@ impl<S: AsyncWrite> ClientAuth<S> {
let name = mech.name().to_owned(); let name = mech.name().to_owned();
if mech_names.iter().any(|name1| *name1 == name) { if mech_names.iter().any(|name1| *name1 == name) {
println!("SASL mechanism selected: {:?}", name); println!("SASL mechanism selected: {:?}", name);
let initial = try!(mech.initial()); let initial = mech.initial()?;
let mut this = ClientAuth { let mut this = ClientAuth {
state: ClientAuthState::Invalid, state: ClientAuthState::Invalid,
mechanism: mech, mechanism: mech,
@ -111,7 +111,7 @@ impl<S: AsyncRead + AsyncWrite> Future for ClientAuth<S> {
match stream.poll() { match stream.poll() {
Ok(Async::Ready(Some(Packet::Stanza(stanza)))) => { Ok(Async::Ready(Some(Packet::Stanza(stanza)))) => {
if let Ok(challenge) = Challenge::try_from(stanza.clone()) { if let Ok(challenge) = Challenge::try_from(stanza.clone()) {
let response = try!(self.mechanism.response(&challenge.data)); let response = self.mechanism.response(&challenge.data)?;
self.send(stream, Response { data: response }); self.send(stream, Response { data: response });
self.poll() self.poll()
} else if let Ok(_) = Success::try_from(stanza.clone()) { } else if let Ok(_) = Success::try_from(stanza.clone()) {

View file

@ -45,7 +45,7 @@ impl Client {
/// Start polling the returned instance so that it will connect /// Start polling the returned instance so that it will connect
/// and yield events. /// and yield events.
pub fn new(jid: &str, password: &str, handle: Handle) -> Result<Self, JidParseError> { pub fn new(jid: &str, password: &str, handle: Handle) -> Result<Self, JidParseError> {
let jid = try!(Jid::from_str(jid)); let jid = Jid::from_str(jid)?;
let password = password.to_owned(); let password = password.to_owned();
let connect = Self::make_connect(jid.clone(), password.clone(), handle); let connect = Self::make_connect(jid.clone(), password.clone(), handle);
Ok(Client { Ok(Client {

View file

@ -42,7 +42,7 @@ impl Component {
/// Start polling the returned instance so that it will connect /// Start polling the returned instance so that it will connect
/// and yield events. /// and yield events.
pub fn new(jid: &str, password: &str, server: &str, port: u16, handle: Handle) -> Result<Self, JidParseError> { pub fn new(jid: &str, password: &str, server: &str, port: u16, handle: Handle) -> Result<Self, JidParseError> {
let jid = try!(Jid::from_str(jid)); let jid = Jid::from_str(jid)?;
let password = password.to_owned(); let password = password.to_owned();
let connect = Self::make_connect(jid.clone(), password, server, port, handle); let connect = Self::make_connect(jid.clone(), password, server, port, handle);
Ok(Component { Ok(Component {

View file

@ -18,14 +18,10 @@ pub struct Connecter {
impl Connecter { impl Connecter {
pub fn from_lookup(handle: Handle, domain: &str, srv: &str, fallback_port: u16) -> Result<Connecter, String> { pub fn from_lookup(handle: Handle, domain: &str, srv: &str, fallback_port: u16) -> Result<Connecter, String> {
let domain = try!( let domain = DNameBuf::from_str(domain)
DNameBuf::from_str(domain) .map_err(|e| format!("{}", e))?;
.map_err(|e| format!("{}", e)) let srv = DNameBuf::from_str(srv)
); .map_err(|e| format!("{}", e))?;
let srv = try!(
DNameBuf::from_str(srv)
.map_err(|e| format!("{}", e))
);
let resolver = Resolver::new(&handle); let resolver = Resolver::new(&handle);
let lookup = lookup_srv(resolver.clone(), srv, domain, fallback_port); let lookup = lookup_srv(resolver.clone(), srv, domain, fallback_port);