diff --git a/examples/autoreconnect.rs b/examples/autoreconnect.rs index 0c0aba7..387007b 100644 --- a/examples/autoreconnect.rs +++ b/examples/autoreconnect.rs @@ -13,20 +13,20 @@ fn main() { .. Default::default() }; let server = Arc::new(IrcServer::from_config(config).unwrap()); - // FIXME: if set_keepalive is stabilized, this can be readded. + // FIXME: if set_keepalive is stabilized, this can be readded. // server.conn().set_keepalive(Some(5)).unwrap(); let server = server.clone(); - let _ = spawn(move || { + let _ = spawn(move || { server.identify().unwrap(); loop { let mut quit = false; for msg in server.iter() { match msg { - Ok(msg) => { + Ok(msg) => { print!("{}", msg.into_string()); match (&msg).into() { - Ok(Command::PRIVMSG(_, msg)) => if msg.contains("bye") { - server.send_quit("").unwrap() + Ok(Command::PRIVMSG(_, msg)) => if msg.contains("bye") { + server.send_quit("").unwrap() }, Ok(Command::ERROR(ref msg)) if msg.contains("Quit") => quit = true, _ => (), @@ -39,5 +39,5 @@ fn main() { server.reconnect().unwrap(); server.identify().unwrap(); } - }).join(); + }).join(); } diff --git a/examples/multithreaded.rs b/examples/multithreaded.rs index e62bc8e..4602540 100644 --- a/examples/multithreaded.rs +++ b/examples/multithreaded.rs @@ -15,7 +15,7 @@ fn main() { let server = Arc::new(IrcServer::from_config(config).unwrap()); server.identify().unwrap(); let server = server.clone(); - let _ = spawn(move || { + let _ = spawn(move || { for msg in server.iter() { print!("{}", msg.unwrap().into_string()); } diff --git a/examples/simple.rs b/examples/simple.rs index 75de009..a15affd 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -11,7 +11,7 @@ fn main() { channels: Some(vec![format!("#vana")]), .. Default::default() }; - let server = IrcServer::from_config(config).unwrap(); + let server = IrcServer::from_config(config).unwrap(); server.identify().unwrap(); for message in server.iter() { let message = message.unwrap(); // We'll just panic if there's an error. diff --git a/examples/simple_cmd.rs b/examples/simple_cmd.rs index aed3acb..068b35b 100644 --- a/examples/simple_cmd.rs +++ b/examples/simple_cmd.rs @@ -11,7 +11,7 @@ fn main() { channels: Some(vec![format!("#vana")]), .. Default::default() }; - let server = IrcServer::from_config(config).unwrap(); + let server = IrcServer::from_config(config).unwrap(); server.identify().unwrap(); for command in server.iter_cmd() { // Use of unwrap() on the results of iter_cmd() is discouraged since response codes will be diff --git a/examples/tweeter.rs b/examples/tweeter.rs index 1846822..81e92e5 100644 --- a/examples/tweeter.rs +++ b/examples/tweeter.rs @@ -11,13 +11,13 @@ fn main() { server: Some(format!("irc.fyrechat.net")), channels: Some(vec![format!("#vana")]), .. Default::default() - }; + }; let server = Arc::new(IrcServer::from_config(config).unwrap()); server.identify().unwrap(); let server2 = server.clone(); // Let's set up a loop that just prints the messages. - spawn(move || { - server2.iter().map(|m| print!("{}", m.unwrap().into_string())).count(); + spawn(move || { + server2.iter().map(|m| print!("{}", m.unwrap().into_string())).count(); }); loop { server.send_privmsg("#vana", "TWEET TWEET").unwrap(); diff --git a/src/client/conn.rs b/src/client/conn.rs index 73d76e2..fbc93d6 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -79,7 +79,7 @@ impl Connection, BufWriter> { Ok(()) } - + /* FIXME: removed until set_keepalive is stabilized. /// Sets the keepalive for the network stream. @@ -120,7 +120,7 @@ impl Connection { let msg: Message = to_msg.into(); let data = match encoding.encode(&msg.into_string(), EncoderTrap::Replace) { Ok(data) => data, - Err(data) => return Err(Error::new(ErrorKind::InvalidInput, + Err(data) => return Err(Error::new(ErrorKind::InvalidInput, &format!("Failed to encode {} as {}.", data, encoding.name())[..] )) }; @@ -129,7 +129,7 @@ impl Connection { writer.flush() } - /// Sends a message over this connection. + /// Sends a message over this connection. #[cfg(not(feature = "encode"))] pub fn send>(&self, to_msg: M) -> Result<()> { let mut writer = self.writer.lock().unwrap(); @@ -152,7 +152,7 @@ impl Connection { match encoding.decode(&buf, DecoderTrap::Replace) { _ if buf.is_empty() => Err(Error::new(ErrorKind::Other, "EOF")), Ok(data) => Ok(data), - Err(data) => return Err(Error::new(ErrorKind::InvalidInput, + Err(data) => return Err(Error::new(ErrorKind::InvalidInput, &format!("Failed to decode {} as {}.", data, encoding.name())[..] )) } @@ -187,7 +187,7 @@ impl Connection { fn ssl_to_io(res: StdResult) -> Result { match res { Ok(x) => Ok(x), - Err(e) => Err(Error::new(ErrorKind::Other, + Err(e) => Err(Error::new(ErrorKind::Other, &format!("An SSL error occurred. ({})", e.description())[..] )), } @@ -250,7 +250,7 @@ mod test { let data = String::from_utf8(conn.writer().to_vec()).unwrap(); assert_eq!(&data[..], "PRIVMSG test :Testing!\r\n"); } - + #[test] #[cfg(not(feature = "encode"))] fn send_str() { diff --git a/src/client/data/caps.rs b/src/client/data/caps.rs index 4d72797..0a27255 100644 --- a/src/client/data/caps.rs +++ b/src/client/data/caps.rs @@ -1,7 +1,7 @@ //! Enumeration of all supported IRCv3 capability extensions. /// List of all supported IRCv3 capability extensions from the -/// [IRCv3 specifications](http://ircv3.net/irc/). +/// [IRCv3 specifications](http://ircv3.net/irc/). #[derive(Debug, PartialEq)] pub enum Capability { /// [multi-prefix](http://ircv3.net/specs/extensions/multi-prefix-3.1.html) diff --git a/src/client/data/command.rs b/src/client/data/command.rs index ddd794b..2c719c7 100644 --- a/src/client/data/command.rs +++ b/src/client/data/command.rs @@ -461,7 +461,7 @@ impl<'a> From<&'a Message> for Result { } else if m.args.len() == 2 { Command::JOIN(m.args[0].clone(), Some(m.args[1].clone()), None) } else if m.args.len() == 3 { - Command::JOIN(m.args[0].clone(), Some(m.args[1].clone()), + Command::JOIN(m.args[0].clone(), Some(m.args[1].clone()), Some(m.args[2].clone())) } else { return Err(invalid_input()) @@ -750,7 +750,7 @@ impl<'a> From<&'a Message> for Result { } else if m.args.len() == 1 { Command::WHOWAS(m.args[0].clone(), None, Some(suffix.clone())) } else if m.args.len() == 2 { - Command::WHOWAS(m.args[0].clone(), Some(m.args[1].clone()), + Command::WHOWAS(m.args[0].clone(), Some(m.args[1].clone()), Some(suffix.clone())) } else { return Err(invalid_input()) @@ -760,7 +760,7 @@ impl<'a> From<&'a Message> for Result { } else if m.args.len() == 2 { Command::WHOWAS(m.args[0].clone(), None, Some(m.args[1].clone())) } else if m.args.len() == 3 { - Command::WHOWAS(m.args[0].clone(), Some(m.args[1].clone()), + Command::WHOWAS(m.args[0].clone(), Some(m.args[1].clone()), Some(m.args[2].clone())) } else { return Err(invalid_input()) @@ -854,7 +854,7 @@ impl<'a> From<&'a Message> for Result { } else if m.args.len() == 1 { Command::SUMMON(m.args[0].clone(), Some(suffix.clone()), None) } else if m.args.len() == 2 { - Command::SUMMON(m.args[0].clone(), Some(m.args[1].clone()), + Command::SUMMON(m.args[0].clone(), Some(m.args[1].clone()), Some(suffix.clone())) } else { return Err(invalid_input()) @@ -864,7 +864,7 @@ impl<'a> From<&'a Message> for Result { } else if m.args.len() == 2 { Command::SUMMON(m.args[0].clone(), Some(m.args[1].clone()), None) } else if m.args.len() == 3 { - Command::SUMMON(m.args[0].clone(), Some(m.args[1].clone()), + Command::SUMMON(m.args[0].clone(), Some(m.args[1].clone()), Some(m.args[2].clone())) } else { return Err(invalid_input()) @@ -1044,7 +1044,7 @@ impl<'a> From<&'a Message> for Result { } else if m.args.len() == 2 { if let Ok(cmd) = m.args[0].parse() { match m.suffix { - Some(ref suffix) => Command::CAP(None, cmd, Some(m.args[1].clone()), + Some(ref suffix) => Command::CAP(None, cmd, Some(m.args[1].clone()), Some(suffix.clone())), None => Command::CAP(None, cmd, Some(m.args[1].clone()), None), } @@ -1060,7 +1060,7 @@ impl<'a> From<&'a Message> for Result { } else if m.args.len() == 3 { if let Ok(cmd) = m.args[1].parse() { match m.suffix { - Some(ref suffix) => Command::CAP(Some(m.args[0].clone()), cmd, + Some(ref suffix) => Command::CAP(Some(m.args[0].clone()), cmd, Some(m.args[2].clone()), Some(suffix.clone())), None => Command::CAP(Some(m.args[0].clone()), cmd, Some(m.args[2].clone()), diff --git a/src/client/data/config.rs b/src/client/data/config.rs index 556011c..86fc443 100644 --- a/src/client/data/config.rs +++ b/src/client/data/config.rs @@ -50,7 +50,7 @@ impl Config { let mut file = try!(File::open(path)); let mut data = String::new(); try!(file.read_to_string(&mut data)); - decode(&data[..]).map_err(|_| + decode(&data[..]).map_err(|_| Error::new(ErrorKind::InvalidInput, "Failed to decode configuration file.") ) } @@ -128,7 +128,7 @@ impl Config { /// Gets the channels to join upon connection. /// This defaults to an empty vector if it's not specified. pub fn channels(&self) -> Vec<&str> { - self.channels.as_ref().map(|v| v.iter().map(|s| &s[..]).collect()).unwrap_or(vec![]) + self.channels.as_ref().map(|v| v.iter().map(|s| &s[..]).collect()).unwrap_or(vec![]) } /// Gets the user modes to set on connect specified in the configuration. diff --git a/src/client/data/message.rs b/src/client/data/message.rs index 66e8e3d..9bc1ae1 100644 --- a/src/client/data/message.rs +++ b/src/client/data/message.rs @@ -45,7 +45,7 @@ impl Message { } } - /// Gets the nickname of the message source, if it exists. + /// Gets the nickname of the message source, if it exists. pub fn get_source_nickname(&self) -> Option<&str> { self.prefix.as_ref().and_then(|s| s.find('!').map(|i| &s[..i])) } diff --git a/src/client/data/response.rs b/src/client/data/response.rs index cd10151..f0567e6 100644 --- a/src/client/data/response.rs +++ b/src/client/data/response.rs @@ -74,7 +74,7 @@ pub enum Response { RPL_ENDOFEXCEPTLIST = 349, /// 351 . : RPL_VERSION = 351, - /// 352 ( "H" / "G" > ["*"] [ ( "@" / "+" ) ] + /// 352 ( "H" / "G" > ["*"] [ ( "@" / "+" ) ] /// : RPL_WHOREPLY = 352, /// 315 :End of WHO list @@ -95,7 +95,7 @@ pub enum Response { RPL_INFO = 371, /// 374 :End of INFO list RPL_ENDOFINFO = 374, - /// 375 :- Message of the day - + /// 375 :- Message of the day - RPL_MOTDSTART = 375, /// 372 :- RPL_MOTD = 372, @@ -190,7 +190,7 @@ pub enum Response { /// 733 :End of MONITOR list RPL_ENDOFMONLIST = 733, - + // Error replies /// 401 :No such nick/channel ERR_NOSUCHNICK = 401, @@ -304,11 +304,11 @@ pub enum Response { impl Response { /// Gets a response from a message. - pub fn from_message(m: &Message) -> Option { + pub fn from_message(m: &Message) -> Option { m.command.parse().ok() } - /// Determines whether or not this response is an error response. + /// Determines whether or not this response is an error response. pub fn is_error(&self) -> bool { *self as u16 >= 400 } @@ -320,12 +320,12 @@ impl FromStr for Response { if let Ok(rc) = s.parse::() { // This wall of text was brought to you by the removal of FromPrimitive. if (rc > 0 && rc < 5) || (rc > 200 && rc < 213) || rc == 219 || rc == 221 || rc == 234 - || rc == 235 || rc == 242 || rc == 243 || (rc > 250 && rc < 260) || - (rc > 260 && rc < 264) || (rc > 300 && rc < 307) || - (rc > 310 && rc < 326 && rc != 320) || rc == 331 || rc == 332 || rc == 341 || - rc == 342 || (rc > 345 && rc < 354 && rc != 350) || - (rc > 363 && rc < 377 && rc != 370) || (rc > 380 && rc < 384) || - (rc > 390 && rc < 396) || (rc > 400 && rc < 415 && rc != 410) || + || rc == 235 || rc == 242 || rc == 243 || (rc > 250 && rc < 260) || + (rc > 260 && rc < 264) || (rc > 300 && rc < 307) || + (rc > 310 && rc < 326 && rc != 320) || rc == 331 || rc == 332 || rc == 341 || + rc == 342 || (rc > 345 && rc < 354 && rc != 350) || + (rc > 363 && rc < 377 && rc != 370) || (rc > 380 && rc < 384) || + (rc > 390 && rc < 396) || (rc > 400 && rc < 415 && rc != 410) || (rc > 420 && rc < 425) || (rc > 430 && rc < 434) || rc == 436 || rc == 437 || (rc > 440 && rc < 447) || rc == 451 || (rc > 460 && rc < 468) || (rc > 470 && rc < 479) || (rc > 480 && rc < 486) || rc == 491 || rc == 501 || @@ -336,7 +336,7 @@ impl FromStr for Response { } } else { Err("Failed to parse response code.") - } + } } } diff --git a/src/client/data/user.rs b/src/client/data/user.rs index b12c684..6032e01 100644 --- a/src/client/data/user.rs +++ b/src/client/data/user.rs @@ -32,7 +32,7 @@ impl User { nickname: nickname, username: username, hostname: hostname, - access_levels: { + access_levels: { let mut ranks = ranks.clone(); ranks.push(AccessLevel::Member); ranks @@ -96,7 +96,7 @@ impl User { /// Adds an access level to the list, and updates the highest level if necessary. fn add_access_level(&mut self, level: AccessLevel) { if level > self.highest_access_level() { - self.highest_access_level = level + self.highest_access_level = level } self.access_levels.push(level.clone()) } @@ -178,7 +178,7 @@ impl PartialOrd for AccessLevel { } }, &AccessLevel::Member => Some(Less), - } + } } } diff --git a/src/client/mod.rs b/src/client/mod.rs index 9290a72..7108cd4 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -15,7 +15,7 @@ pub mod prelude { #[cfg(test)] pub mod test { use std::io::{BufReader, Empty, empty}; - + pub fn buf_empty() -> BufReader { BufReader::new(empty()) } diff --git a/src/client/server/mod.rs b/src/client/server/mod.rs index 05c3c2f..f01fbe6 100644 --- a/src/client/server/mod.rs +++ b/src/client/server/mod.rs @@ -125,7 +125,7 @@ impl IrcServer { if resp == Response::RPL_NAMREPLY { if cfg!(not(feature = "nochanlists")) { if let Some(users) = msg.suffix.clone() { - if msg.args.len() == 3 { + if msg.args.len() == 3 { // TODO: replace with slice pattern matching when/if stable let ref chan = msg.args[2]; for user in users.split(" ") { @@ -133,7 +133,7 @@ impl IrcServer { Some(vec) => { vec.push(User::new(user)); false }, None => true, } { - self.chanlists.lock().unwrap().insert(chan.clone(), + self.chanlists.lock().unwrap().insert(chan.clone(), vec!(User::new(user))); } } @@ -168,7 +168,7 @@ impl IrcServer { } if &msg.command[..] == "PING" { self.send(PONG(msg.suffix.as_ref().unwrap().to_owned(), None)).unwrap(); - } else if cfg!(not(feature = "nochanlists")) && + } else if cfg!(not(feature = "nochanlists")) && (&msg.command[..] == "JOIN" || &msg.command[..] == "PART") { let chan = match msg.suffix { Some(ref suffix) => &suffix[..], @@ -234,7 +234,7 @@ impl IrcServer { self.send_ctcp_internal(resp, "SOURCE"); }, "PING" => self.send_ctcp_internal(resp, &format!("PING {}", tokens[1])), - "TIME" => self.send_ctcp_internal(resp, &format!("TIME :{}", + "TIME" => self.send_ctcp_internal(resp, &format!("TIME :{}", now().rfc822z())), "USERINFO" => self.send_ctcp_internal(resp, &format!("USERINFO :{}", self.config.user_info())), @@ -293,7 +293,7 @@ impl<'a, T: IrcRead, U: IrcWrite> Iterator for ServerIterator<'a, T, U> { self.server.handle_message(&msg); Ok(msg) }, - Err(_) => Err(Error::new(ErrorKind::InvalidInput, + Err(_) => Err(Error::new(ErrorKind::InvalidInput, &format!("Failed to parse message. (Message: {})", msg)[..] )) } diff --git a/src/client/server/utils.rs b/src/client/server/utils.rs index 187d97a..e2a0c5e 100644 --- a/src/client/server/utils.rs +++ b/src/client/server/utils.rs @@ -130,7 +130,7 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> { self.send(INVITE(nick.to_owned(), chan.to_owned())) } - /// Quits the server entirely with a message. + /// Quits the server entirely with a message. /// This defaults to `Powered by Rust.` if none is specified. fn send_quit(&self, msg: &str) -> Result<()> where Self: Sized { self.send(QUIT(Some(if msg.len() == 0 { @@ -212,7 +212,7 @@ mod test { #[test] fn identify() { - let server = IrcServer::from_connection(test_config(), + let server = IrcServer::from_connection(test_config(), Connection::new(buf_empty(), Vec::new())); server.identify().unwrap(); assert_eq!(&get_server_value(server)[..], "CAP END\r\nNICK :test\r\n\