Purged try! from code (replaced with ?).
This commit is contained in:
parent
52035bd31e
commit
196d6425bd
3 changed files with 21 additions and 21 deletions
|
@ -77,9 +77,9 @@ pub struct Config {
|
|||
impl Config {
|
||||
/// Loads a JSON configuration from the desired path.
|
||||
pub fn load<P: AsRef<Path>>(path: P) -> Result<Config> {
|
||||
let mut file = try!(File::open(path));
|
||||
let mut file = File::open(path)?;
|
||||
let mut data = String::new();
|
||||
try!(file.read_to_string(&mut data));
|
||||
file.read_to_string(&mut data)?;
|
||||
serde_json::from_str(&data[..]).map_err(|_| {
|
||||
Error::new(
|
||||
ErrorKind::InvalidInput,
|
||||
|
@ -90,14 +90,14 @@ impl Config {
|
|||
|
||||
/// Saves a JSON configuration to the desired path.
|
||||
pub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()> {
|
||||
let mut file = try!(File::create(path));
|
||||
let mut file = File::create(path)?;
|
||||
file.write_all(
|
||||
try!(serde_json::to_string(self).map_err(|_| {
|
||||
serde_json::to_string(self).map_err(|_| {
|
||||
Error::new(
|
||||
ErrorKind::InvalidInput,
|
||||
"Failed to encode configuration file.",
|
||||
)
|
||||
})).as_bytes(),
|
||||
})?.as_bytes(),
|
||||
).map_err(|e| e.into())
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ impl<'a> Server for ServerState {
|
|||
Self: Sized,
|
||||
{
|
||||
let msg = &msg.into();
|
||||
try!(self.handle_sent_message(&msg));
|
||||
self.handle_sent_message(&msg)?;
|
||||
Ok((&self.outgoing).send(
|
||||
ServerState::sanitize(&msg.to_string())
|
||||
.into(),
|
||||
|
@ -236,9 +236,9 @@ impl ServerState {
|
|||
body[1..end].split(' ').collect()
|
||||
};
|
||||
if target.starts_with('#') {
|
||||
try!(self.handle_ctcp(target, tokens))
|
||||
self.handle_ctcp(target, tokens)?
|
||||
} else if let Some(user) = msg.source_nickname() {
|
||||
try!(self.handle_ctcp(user, tokens))
|
||||
self.handle_ctcp(user, tokens)?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ impl ServerState {
|
|||
if *index >= alt_nicks.len() {
|
||||
panic!("All specified nicknames were in use or disallowed.")
|
||||
} else {
|
||||
try!(self.send(NICK(alt_nicks[*index].to_owned())));
|
||||
self.send(NICK(alt_nicks[*index].to_owned()))?;
|
||||
*index += 1;
|
||||
}
|
||||
}
|
||||
|
@ -288,15 +288,15 @@ impl ServerState {
|
|||
let mut index = self.alt_nick_index.write().unwrap();
|
||||
if self.config().should_ghost() && *index != 0 {
|
||||
for seq in &self.config().ghost_sequence() {
|
||||
try!(self.send(NICKSERV(format!(
|
||||
self.send(NICKSERV(format!(
|
||||
"{} {} {}",
|
||||
seq,
|
||||
self.config().nickname(),
|
||||
self.config().nick_password()
|
||||
))));
|
||||
)))?;
|
||||
}
|
||||
*index = 0;
|
||||
try!(self.send(NICK(self.config().nickname().to_owned())))
|
||||
self.send(NICK(self.config().nickname().to_owned()))?
|
||||
}
|
||||
self.send(NICKSERV(
|
||||
format!("IDENTIFY {}", self.config().nick_password()),
|
||||
|
@ -430,10 +430,10 @@ impl ServerState {
|
|||
} else if tokens[0].eq_ignore_ascii_case("VERSION") {
|
||||
self.send_ctcp_internal(resp, &format!("VERSION {}", self.config().version()))
|
||||
} else if tokens[0].eq_ignore_ascii_case("SOURCE") {
|
||||
try!(self.send_ctcp_internal(
|
||||
self.send_ctcp_internal(
|
||||
resp,
|
||||
&format!("SOURCE {}", self.config().source()),
|
||||
));
|
||||
)?;
|
||||
self.send_ctcp_internal(resp, "SOURCE")
|
||||
} else if tokens[0].eq_ignore_ascii_case("PING") && tokens.len() > 1 {
|
||||
self.send_ctcp_internal(resp, &format!("PING {}", tokens[1]))
|
||||
|
|
|
@ -54,16 +54,16 @@ pub trait ServerExt: Server {
|
|||
Self: Sized,
|
||||
{
|
||||
// Send a CAP END to signify that we're IRCv3-compliant (and to end negotiations!).
|
||||
try!(self.send(CAP(None, END, None, None)));
|
||||
self.send(CAP(None, END, None, None))?;
|
||||
if self.config().password() != "" {
|
||||
try!(self.send(PASS(self.config().password().to_owned())));
|
||||
self.send(PASS(self.config().password().to_owned()))?;
|
||||
}
|
||||
try!(self.send(NICK(self.config().nickname().to_owned())));
|
||||
try!(self.send(USER(
|
||||
self.send(NICK(self.config().nickname().to_owned()))?;
|
||||
self.send(USER(
|
||||
self.config().username().to_owned(),
|
||||
"0".to_owned(),
|
||||
self.config().real_name().to_owned(),
|
||||
)));
|
||||
))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ pub trait ServerExt: Server {
|
|||
Self: Sized,
|
||||
{
|
||||
for line in message.split("\r\n") {
|
||||
try!(self.send(PRIVMSG(target.to_owned(), line.to_owned())))
|
||||
self.send(PRIVMSG(target.to_owned(), line.to_owned()))?
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ pub trait ServerExt: Server {
|
|||
Self: Sized,
|
||||
{
|
||||
for line in message.split("\r\n") {
|
||||
try!(self.send(NOTICE(target.to_owned(), line.to_owned())))
|
||||
self.send(NOTICE(target.to_owned(), line.to_owned()))?
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue