From 388628d62a193814a5eecd256c77736e3bf55e0b Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Mon, 19 Jun 2017 13:46:01 -0400 Subject: [PATCH] Applied a bunch of clippy lints. --- examples/multithreaded.rs | 6 +- examples/simple.rs | 8 +- examples/simple_ssl.rs | 6 +- examples/tweeter.rs | 6 +- src/client/conn.rs | 6 +- src/client/data/command.rs | 256 ++++++++++++++++++------------------ src/client/data/message.rs | 4 +- src/client/data/response.rs | 10 +- src/client/data/user.rs | 2 +- src/client/server/mod.rs | 35 +++-- 10 files changed, 168 insertions(+), 171 deletions(-) diff --git a/examples/multithreaded.rs b/examples/multithreaded.rs index 7edc889..33e30b3 100644 --- a/examples/multithreaded.rs +++ b/examples/multithreaded.rs @@ -6,9 +6,9 @@ use irc::client::prelude::*; fn main() { let config = Config { - nickname: Some(format!("pickles")), - server: Some(format!("irc.fyrechat.net")), - channels: Some(vec![format!("#vana")]), + nickname: Some("pickles".to_owned()), + server: Some("irc.fyrechat.net".to_owned()), + channels: Some(vec!["#vana".to_owned()]), .. Default::default() }; let server = IrcServer::from_config(config).unwrap(); diff --git a/examples/simple.rs b/examples/simple.rs index b983755..2b06f96 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -5,10 +5,10 @@ use irc::client::prelude::*; fn main() { let config = Config { - nickname: Some(format!("pickles")), - alt_nicks: Some(vec![format!("bananas"), format!("apples")]), - server: Some(format!("irc.fyrechat.net")), - channels: Some(vec![format!("#vana")]), + nickname: Some("pickles".to_owned()), + alt_nicks: Some(vec!["bananas".to_owned(), "apples".to_owned()]), + server: Some("irc.fyrechat.net".to_owned()), + channels: Some(vec!["#vana".to_owned()]), .. Default::default() }; let server = IrcServer::from_config(config).unwrap(); diff --git a/examples/simple_ssl.rs b/examples/simple_ssl.rs index 0b2b898..867fd68 100644 --- a/examples/simple_ssl.rs +++ b/examples/simple_ssl.rs @@ -5,9 +5,9 @@ use irc::client::prelude::*; fn main() { let config = Config { - nickname: Some(format!("pickles")), - server: Some(format!("irc.fyrechat.net")), - channels: Some(vec![format!("#vana")]), + nickname: Some("pickles".to_owned()), + server: Some("irc.fyrechat.net".to_owned()), + channels: Some(vec!["#vana".to_owned()]), port: Some(6697), use_ssl: Some(true), .. Default::default() diff --git a/examples/tweeter.rs b/examples/tweeter.rs index 15dc76a..771c97d 100644 --- a/examples/tweeter.rs +++ b/examples/tweeter.rs @@ -7,9 +7,9 @@ use irc::client::prelude::*; fn main() { let config = Config { - nickname: Some(format!("pickles")), - server: Some(format!("irc.fyrechat.net")), - channels: Some(vec![format!("#vana")]), + nickname: Some("pickles".to_owned()), + server: Some("irc.fyrechat.net".to_owned()), + channels: Some(vec!["#vana".to_owned()]), .. Default::default() }; let server = IrcServer::from_config(config).unwrap(); diff --git a/src/client/conn.rs b/src/client/conn.rs index ea1b560..478136d 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -1,4 +1,4 @@ -//! Thread-safe connections on IrcStreams. +//! Thread-safe connections on `IrcStreams`. #[cfg(feature = "ssl")] use std::error::Error as StdError; use std::io::prelude::*; use std::io::{BufReader, BufWriter, Cursor, Result}; @@ -50,7 +50,7 @@ type NetReader = BufReader; type NetWriter = BufWriter; type NetReadWritePair = (NetReader, NetWriter); -/// A thread-safe connection over a buffered NetStream. +/// A thread-safe connection over a buffered `NetStream`. pub struct NetConnection { host: Mutex, port: Mutex, @@ -105,7 +105,7 @@ impl NetConnection { } } -/// Converts a Result into an Result. +/// Converts a `Result` into an `io::Result`. #[cfg(feature = "ssl")] fn ssl_to_io(res: StdResult) -> Result { match res { diff --git a/src/client/data/command.rs b/src/client/data/command.rs index 1b0c034..2c506c3 100644 --- a/src/client/data/command.rs +++ b/src/client/data/command.rs @@ -175,7 +175,7 @@ pub enum Command { Raw(String, Vec, Option), } -fn stringify(cmd: &str, args: Vec<&str>, suffix: Option<&str>) -> String { +fn stringify(cmd: &str, args: &[&str], suffix: Option<&str>) -> String { let args = args.join(" "); let sp = if args.is_empty() { "" } else { " " }; match suffix { @@ -188,236 +188,236 @@ fn stringify(cmd: &str, args: Vec<&str>, suffix: Option<&str>) -> String { impl<'a> From<&'a Command> for String { fn from(cmd: &'a Command) -> String { match *cmd { - Command::PASS(ref p) => stringify("PASS", vec![], Some(p)), - Command::NICK(ref n) => stringify("NICK", vec![], Some(n)), + Command::PASS(ref p) => stringify("PASS", &[], Some(p)), + Command::NICK(ref n) => stringify("NICK", &[], Some(n)), Command::USER(ref u, ref m, ref r) => - stringify("USER", vec![u, m, "*"], Some(r)), + stringify("USER", &[u, m, "*"], Some(r)), Command::OPER(ref u, ref p) => - stringify("OPER", vec![u], Some(p)), + stringify("OPER", &[u], Some(p)), Command::MODE(ref t, ref m, Some(ref p)) => - stringify("MODE", vec![t, m, p], None), + stringify("MODE", &[t, m, p], None), Command::MODE(ref t, ref m, None) => - stringify("MODE", vec![t, m], None), + stringify("MODE", &[t, m], None), Command::SERVICE(ref n, ref r, ref d, ref t, ref re, ref i) => - stringify("SERVICE", vec![n, r, d, t, re], Some(i)), - Command::QUIT(Some(ref m)) => stringify("QUIT", vec![], Some(m)), - Command::QUIT(None) => stringify("QUIT", vec![], None), + stringify("SERVICE", &[n, r, d, t, re], Some(i)), + Command::QUIT(Some(ref m)) => stringify("QUIT", &[], Some(m)), + Command::QUIT(None) => stringify("QUIT", &[], None), Command::SQUIT(ref s, ref c) => - stringify("SQUIT", vec![s], Some(c)), + stringify("SQUIT", &[s], Some(c)), Command::JOIN(ref c, Some(ref k), Some(ref n)) => - stringify("JOIN", vec![c, k], Some(n)), + stringify("JOIN", &[c, k], Some(n)), Command::JOIN(ref c, Some(ref k), None) => - stringify("JOIN", vec![c, k], None), + stringify("JOIN", &[c, k], None), Command::JOIN(ref c, None, Some(ref n)) => - stringify("JOIN", vec![c], Some(n)), + stringify("JOIN", &[c], Some(n)), Command::JOIN(ref c, None, None) => - stringify("JOIN", vec![c], None), + stringify("JOIN", &[c], None), Command::PART(ref c, Some(ref m)) => - stringify("PART", vec![c], Some(m)), + stringify("PART", &[c], Some(m)), Command::PART(ref c, None) => - stringify("PART", vec![c], None), + stringify("PART", &[c], None), Command::TOPIC(ref c, Some(ref t)) => - stringify("TOPIC", vec![c], Some(t)), + stringify("TOPIC", &[c], Some(t)), Command::TOPIC(ref c, None) => - stringify("TOPIC", vec![c], None), + stringify("TOPIC", &[c], None), Command::NAMES(Some(ref c), Some(ref t)) => - stringify("NAMES", vec![c], Some(t)), + stringify("NAMES", &[c], Some(t)), Command::NAMES(Some(ref c), None) => - stringify("NAMES", vec![c], None), - Command::NAMES(None, _) => stringify("NAMES", vec![], None), + stringify("NAMES", &[c], None), + Command::NAMES(None, _) => stringify("NAMES", &[], None), Command::LIST(Some(ref c), Some(ref t)) => - stringify("LIST", vec![c], Some(t)), + stringify("LIST", &[c], Some(t)), Command::LIST(Some(ref c), None) => - stringify("LIST", vec![c], None), - Command::LIST(None, _) => stringify("LIST", vec![], None), + stringify("LIST", &[c], None), + Command::LIST(None, _) => stringify("LIST", &[], None), Command::INVITE(ref n, ref c) => - stringify("INVITE", vec![n, c], None), + stringify("INVITE", &[n, c], None), Command::KICK(ref c, ref n, Some(ref r)) => - stringify("KICK", vec![c, n], Some(r)), + stringify("KICK", &[c, n], Some(r)), Command::KICK(ref c, ref n, None) => - stringify("KICK", vec![c, n], None), + stringify("KICK", &[c, n], None), Command::PRIVMSG(ref t, ref m) => - stringify("PRIVMSG", vec![t], Some(m)), + stringify("PRIVMSG", &[t], Some(m)), Command::NOTICE(ref t, ref m) => - stringify("NOTICE", vec![t], Some(m)), - Command::MOTD(Some(ref t)) => stringify("MOTD", vec![], Some(t)), - Command::MOTD(None) => stringify("MOTD", vec![], None), + stringify("NOTICE", &[t], Some(m)), + Command::MOTD(Some(ref t)) => stringify("MOTD", &[], Some(t)), + Command::MOTD(None) => stringify("MOTD", &[], None), Command::LUSERS(Some(ref m), Some(ref t)) => - stringify("LUSERS", vec![m], Some(t)), + stringify("LUSERS", &[m], Some(t)), Command::LUSERS(Some(ref m), None) => - stringify("LUSERS", vec![m], None), - Command::LUSERS(None, _) => stringify("LUSERS", vec![], None), + stringify("LUSERS", &[m], None), + Command::LUSERS(None, _) => stringify("LUSERS", &[], None), Command::VERSION(Some(ref t)) => - stringify("VERSION", vec![], Some(t)), - Command::VERSION(None) => stringify("VERSION", vec![], None), + stringify("VERSION", &[], Some(t)), + Command::VERSION(None) => stringify("VERSION", &[], None), Command::STATS(Some(ref q), Some(ref t)) => - stringify("STATS", vec![q], Some(t)), + stringify("STATS", &[q], Some(t)), Command::STATS(Some(ref q), None) => - stringify("STATS", vec![q], None), - Command::STATS(None, _) => stringify("STATS", vec![], None), + stringify("STATS", &[q], None), + Command::STATS(None, _) => stringify("STATS", &[], None), Command::LINKS(Some(ref r), Some(ref s)) => - stringify("LINKS", vec![r], Some(s)), + stringify("LINKS", &[r], Some(s)), Command::LINKS(None, Some(ref s)) => - stringify("LINKS", vec![], Some(s)), - Command::LINKS(_, None) => stringify("LINKS", vec![], None), - Command::TIME(Some(ref t)) => stringify("TIME", vec![], Some(t)), - Command::TIME(None) => stringify("TIME", vec![], None), + stringify("LINKS", &[], Some(s)), + Command::LINKS(_, None) => stringify("LINKS", &[], None), + Command::TIME(Some(ref t)) => stringify("TIME", &[], Some(t)), + Command::TIME(None) => stringify("TIME", &[], None), Command::CONNECT(ref t, ref p, Some(ref r)) => - stringify("CONNECT", vec![t, p], Some(r)), + stringify("CONNECT", &[t, p], Some(r)), Command::CONNECT(ref t, ref p, None) => - stringify("CONNECT", vec![t, p], None), - Command::TRACE(Some(ref t)) => stringify("TRACE", vec![], Some(t)), - Command::TRACE(None) => stringify("TRACE", vec![], None), - Command::ADMIN(Some(ref t)) => stringify("ADMIN", vec![], Some(t)), - Command::ADMIN(None) => stringify("ADMIN", vec![], None), - Command::INFO(Some(ref t)) => stringify("INFO", vec![], Some(t)), - Command::INFO(None) => stringify("INFO", vec![], None), + stringify("CONNECT", &[t, p], None), + Command::TRACE(Some(ref t)) => stringify("TRACE", &[], Some(t)), + Command::TRACE(None) => stringify("TRACE", &[], None), + Command::ADMIN(Some(ref t)) => stringify("ADMIN", &[], Some(t)), + Command::ADMIN(None) => stringify("ADMIN", &[], None), + Command::INFO(Some(ref t)) => stringify("INFO", &[], Some(t)), + Command::INFO(None) => stringify("INFO", &[], None), Command::SERVLIST(Some(ref m), Some(ref t)) => - stringify("SERVLIST", vec![m], Some(t)), + stringify("SERVLIST", &[m], Some(t)), Command::SERVLIST(Some(ref m), None) => - stringify("SERVLIST", vec![m], None), + stringify("SERVLIST", &[m], None), Command::SERVLIST(None, _) => - stringify("SERVLIST", vec![], None), + stringify("SERVLIST", &[], None), Command::SQUERY(ref s, ref t) => - stringify("SQUERY", vec![s, t], None), + stringify("SQUERY", &[s, t], None), Command::WHO(Some(ref s), Some(true)) => - stringify("WHO", vec![s, "o"], None), + stringify("WHO", &[s, "o"], None), Command::WHO(Some(ref s), _) => - stringify("WHO", vec![s], None), - Command::WHO(None, _) => stringify("WHO", vec![], None), + stringify("WHO", &[s], None), + Command::WHO(None, _) => stringify("WHO", &[], None), Command::WHOIS(Some(ref t), ref m) => - stringify("WHOIS", vec![t, m], None), + stringify("WHOIS", &[t, m], None), Command::WHOIS(None, ref m) => - stringify("WHOIS", vec![m], None), + stringify("WHOIS", &[m], None), Command::WHOWAS(ref n, Some(ref c), Some(ref t)) => - stringify("WHOWAS", vec![n, c], Some(t)), + stringify("WHOWAS", &[n, c], Some(t)), Command::WHOWAS(ref n, Some(ref c), None) => - stringify("WHOWAS", vec![n, c], None), + stringify("WHOWAS", &[n, c], None), Command::WHOWAS(ref n, None, _) => - stringify("WHOWAS", vec![n], None), + stringify("WHOWAS", &[n], None), Command::KILL(ref n, ref c) => - stringify("KILL", vec![n], Some(c)), + stringify("KILL", &[n], Some(c)), Command::PING(ref s, Some(ref t)) => - stringify("PING", vec![s], Some(t)), - Command::PING(ref s, None) => stringify("PING", vec![], Some(s)), + stringify("PING", &[s], Some(t)), + Command::PING(ref s, None) => stringify("PING", &[], Some(s)), Command::PONG(ref s, Some(ref t)) => - stringify("PONG", vec![s], Some(t)), - Command::PONG(ref s, None) => stringify("PONG", vec![], Some(s)), - Command::ERROR(ref m) => stringify("ERROR", vec![], Some(m)), - Command::AWAY(Some(ref m)) => stringify("AWAY", vec![], Some(m)), - Command::AWAY(None) => stringify("AWAY", vec![], None), - Command::REHASH => stringify("REHASH", vec![], None), - Command::DIE => stringify("DIE", vec![], None), - Command::RESTART => stringify("RESTART", vec![], None), + stringify("PONG", &[s], Some(t)), + Command::PONG(ref s, None) => stringify("PONG", &[], Some(s)), + Command::ERROR(ref m) => stringify("ERROR", &[], Some(m)), + Command::AWAY(Some(ref m)) => stringify("AWAY", &[], Some(m)), + Command::AWAY(None) => stringify("AWAY", &[], None), + Command::REHASH => stringify("REHASH", &[], None), + Command::DIE => stringify("DIE", &[], None), + Command::RESTART => stringify("RESTART", &[], None), Command::SUMMON(ref u, Some(ref t), Some(ref c)) => - stringify("SUMMON", vec![u, t], Some(c)), + stringify("SUMMON", &[u, t], Some(c)), Command::SUMMON(ref u, Some(ref t), None) => - stringify("SUMMON", vec![u, t], None), + stringify("SUMMON", &[u, t], None), Command::SUMMON(ref u, None, _) => - stringify("SUMMON", vec![u], None), - Command::USERS(Some(ref t)) => stringify("USERS", vec![], Some(t)), - Command::USERS(None) => stringify("USERS", vec![], None), - Command::WALLOPS(ref t) => stringify("WALLOPS", vec![], Some(t)), - Command::USERHOST(ref u) => stringify("USERHOST", u.iter().map(|s| &s[..]).collect(), None), - Command::ISON(ref u) => stringify("ISON", u.iter().map(|s| &s[..]).collect(), None), + stringify("SUMMON", &[u], None), + Command::USERS(Some(ref t)) => stringify("USERS", &[], Some(t)), + Command::USERS(None) => stringify("USERS", &[], None), + Command::WALLOPS(ref t) => stringify("WALLOPS", &[], Some(t)), + Command::USERHOST(ref u) => stringify("USERHOST", &u.iter().map(|s| &s[..]).collect::>(), None), + Command::ISON(ref u) => stringify("ISON", &u.iter().map(|s| &s[..]).collect::>(), None), Command::SAJOIN(ref n, ref c) => - stringify("SAJOIN", vec![n, c], None), + stringify("SAJOIN", &[n, c], None), Command::SAMODE(ref t, ref m, Some(ref p)) => - stringify("SAMODE", vec![t, m, p], None), + stringify("SAMODE", &[t, m, p], None), Command::SAMODE(ref t, ref m, None) => - stringify("SAMODE", vec![t, m], None), + stringify("SAMODE", &[t, m], None), Command::SANICK(ref o, ref n) => - stringify("SANICK", vec![o, n], None), + stringify("SANICK", &[o, n], None), Command::SAPART(ref c, ref r) => - stringify("SAPART", vec![c], Some(r)), + stringify("SAPART", &[c], Some(r)), Command::SAQUIT(ref c, ref r) => - stringify("SAQUIT", vec![c], Some(r)), + stringify("SAQUIT", &[c], Some(r)), Command::NICKSERV(ref m) => - stringify("NICKSERV", vec![m], None), + stringify("NICKSERV", &[m], None), Command::CHANSERV(ref m) => - stringify("CHANSERV", vec![m], None), + stringify("CHANSERV", &[m], None), Command::OPERSERV(ref m) => - stringify("OPERSERV", vec![m], None), + stringify("OPERSERV", &[m], None), Command::BOTSERV(ref m) => - stringify("BOTSERV", vec![m], None), + stringify("BOTSERV", &[m], None), Command::HOSTSERV(ref m) => - stringify("HOSTSERV", vec![m], None), + stringify("HOSTSERV", &[m], None), Command::MEMOSERV(ref m) => - stringify("MEMOSERV", vec![m], None), + stringify("MEMOSERV", &[m], None), Command::CAP(None, ref s, None, Some(ref p)) => - stringify("CAP", vec![s.to_str()], Some(p)), + stringify("CAP", &[s.to_str()], Some(p)), Command::CAP(None, ref s, None, None) => - stringify("CAP", vec![s.to_str()], None), + stringify("CAP", &[s.to_str()], None), Command::CAP(Some(ref k), ref s, None, Some(ref p)) => - stringify("CAP", vec![k, s.to_str()], Some(p)), + stringify("CAP", &[k, s.to_str()], Some(p)), Command::CAP(Some(ref k), ref s, None, None) => - stringify("CAP", vec![k, s.to_str()], None), + stringify("CAP", &[k, s.to_str()], None), Command::CAP(None, ref s, Some(ref c), Some(ref p)) => - stringify("CAP", vec![s.to_str(), c], Some(p)), + stringify("CAP", &[s.to_str(), c], Some(p)), Command::CAP(None, ref s, Some(ref c), None) => - stringify("CAP", vec![s.to_str(), c], None), + stringify("CAP", &[s.to_str(), c], None), Command::CAP(Some(ref k), ref s, Some(ref c), Some(ref p)) => - stringify("CAP", vec![k, s.to_str(), c], Some(p)), + stringify("CAP", &[k, s.to_str(), c], Some(p)), Command::CAP(Some(ref k), ref s, Some(ref c), None) => - stringify("CAP", vec![k, s.to_str(), c], None), + stringify("CAP", &[k, s.to_str(), c], None), Command::AUTHENTICATE(ref d) => - stringify("AUTHENTICATE", vec![d], None), + stringify("AUTHENTICATE", &[d], None), Command::ACCOUNT(ref a) => - stringify("ACCOUNT", vec![a], None), + stringify("ACCOUNT", &[a], None), Command::METADATA(ref t, Some(ref c), None, Some(ref p)) => - stringify("METADATA", vec![&t[..], c.to_str()], Some(p)), + stringify("METADATA", &[&t[..], c.to_str()], Some(p)), Command::METADATA(ref t, Some(ref c), None, None) => - stringify("METADATA", vec![&t[..], c.to_str()], None), + stringify("METADATA", &[&t[..], c.to_str()], None), Command::METADATA(ref t, Some(ref c), Some(ref a), Some(ref p)) => stringify( "METADATA", - vec![t, &c.to_str().to_owned()].iter().map(|s| &s[..]) - .chain(a.iter().map(|s| &s[..])).collect(), + &vec![t, &c.to_str().to_owned()].iter().map(|s| &s[..]) + .chain(a.iter().map(|s| &s[..])).collect::>(), Some(p)), Command::METADATA(ref t, Some(ref c), Some(ref a), None) => stringify("METADATA", - vec![t, &c.to_str().to_owned()].iter().map(|s| &s[..]) - .chain(a.iter().map(|s| &s[..])).collect(), + &vec![t, &c.to_str().to_owned()].iter().map(|s| &s[..]) + .chain(a.iter().map(|s| &s[..])).collect::>(), None), Command::METADATA(ref t, None, None, Some(ref p)) => - stringify("METADATA", vec![t], Some(p)), + stringify("METADATA", &[t], Some(p)), Command::METADATA(ref t, None, None, None) => - stringify("METADATA", vec![t], None), + stringify("METADATA", &[t], None), Command::METADATA(ref t, None, Some(ref a), Some(ref p)) => - stringify("METADATA", vec![t].iter().map(|s| &s[..]).chain(a.iter().map(|s| &s[..])).collect(), Some(p)), + stringify("METADATA", &vec![t].iter().map(|s| &s[..]).chain(a.iter().map(|s| &s[..])).collect::>(), Some(p)), Command::METADATA(ref t, None, Some(ref a), None) => - stringify("METADATA", vec![t].iter().map(|s| &s[..]).chain(a.iter().map(|s| &s[..])).collect(), None), + stringify("METADATA", &vec![t].iter().map(|s| &s[..]).chain(a.iter().map(|s| &s[..])).collect::>(), None), Command::MONITOR(ref c, Some(ref t)) => - stringify("MONITOR", vec![c, t], None), + stringify("MONITOR", &[c, t], None), Command::MONITOR(ref c, None) => - stringify("MONITOR", vec![c], None), + stringify("MONITOR", &[c], None), Command::BATCH(ref t, Some(ref c), Some(ref a)) => stringify( - "BATCH", vec![t, &c.to_str().to_owned()].iter().map(|s| &s[..]).chain(a.iter().map(|s| &s[..])).collect(), + "BATCH", &vec![t, &c.to_str().to_owned()].iter().map(|s| &s[..]).chain(a.iter().map(|s| &s[..])).collect::>(), None ), Command::BATCH(ref t, Some(ref c), None) => - stringify("BATCH", vec![t, c.to_str()], None), + stringify("BATCH", &[t, c.to_str()], None), Command::BATCH(ref t, None, Some(ref a)) => stringify("BATCH", - vec![t].iter().map(|s| &s[..]).chain(a.iter().map(|s| &s[..])).collect(), None), + &vec![t].iter().map(|s| &s[..]).chain(a.iter().map(|s| &s[..])).collect::>(), None), Command::BATCH(ref t, None, None) => - stringify("BATCH", vec![t], None), + stringify("BATCH", &[t], None), Command::CHGHOST(ref u, ref h) => - stringify("CHGHOST", vec![u, h], None), + stringify("CHGHOST", &[u, h], None), Command::Response(ref resp, ref a, Some(ref s)) => - stringify(&format!("{}", *resp as u16), a.iter().map(|s| &s[..]).collect(), Some(s)), + stringify(&format!("{}", *resp as u16), &a.iter().map(|s| &s[..]).collect::>(), Some(s)), Command::Response(ref resp, ref a, None) => - stringify(&format!("{}", *resp as u16), a.iter().map(|s| &s[..]).collect(), None), + stringify(&format!("{}", *resp as u16), &a.iter().map(|s| &s[..]).collect::>(), None), Command::Raw(ref c, ref a, Some(ref s)) => - stringify(c, a.iter().map(|s| &s[..]).collect(), Some(s)), + stringify(c, &a.iter().map(|s| &s[..]).collect::>(), Some(s)), Command::Raw(ref c, ref a, None) => - stringify(c, a.iter().map(|s| &s[..]).collect(), None), + stringify(c, &a.iter().map(|s| &s[..]).collect::>(), None), } } } @@ -1448,7 +1448,7 @@ impl BatchSubCommand { match *self { BatchSubCommand::NETSPLIT => "NETSPLIT", BatchSubCommand::NETJOIN => "NETJOIN", - BatchSubCommand::CUSTOM(ref s) => &s, + BatchSubCommand::CUSTOM(ref s) => s, } } } diff --git a/src/client/data/message.rs b/src/client/data/message.rs index 6102ae0..a0d4a77 100644 --- a/src/client/data/message.rs +++ b/src/client/data/message.rs @@ -41,7 +41,7 @@ impl Message { match (s.find('!'), s.find('@'), s.find('.')) { (Some(i), _, _) => Some(&s[..i]), // '!' [ '@' ] (None, Some(i), _) => Some(&s[..i]), // '@' - (None, None, None) => Some(&s), // + (None, None, None) => Some(s), // _ => None // } ) @@ -53,7 +53,7 @@ impl Message { let mut ret = String::new(); if let Some(ref prefix) = self.prefix { ret.push(':'); - ret.push_str(&prefix); + ret.push_str(prefix); ret.push(' '); } let cmd: String = From::from(&self.command); diff --git a/src/client/data/response.rs b/src/client/data/response.rs index 1c92276..43ee113 100644 --- a/src/client/data/response.rs +++ b/src/client/data/response.rs @@ -28,15 +28,15 @@ macro_rules! make_response { make_response! { // Expected replies /// `001 Welcome to the Internet Relay Network !@` - RPL_WELCOME = 001, + RPL_WELCOME = 1, /// `002 Your host is , running version ` - RPL_YOURHOST = 002, + RPL_YOURHOST = 2, /// `003 This server was created ` - RPL_CREATED = 003, + RPL_CREATED = 3, /// `004 available channel modes>` - RPL_MYINFO = 004, + RPL_MYINFO = 4, /// `005 Try server , port ` - RPL_BOUNCE = 005, + RPL_BOUNCE = 5, /// `302 :*1 *( " " )` RPL_USERHOST = 302, /// `303 :*1 *( " " )` diff --git a/src/client/data/user.rs b/src/client/data/user.rs index 5a4d956..60a52f4 100644 --- a/src/client/data/user.rs +++ b/src/client/data/user.rs @@ -39,7 +39,7 @@ impl User { }, highest_access_level: { let mut max = AccessLevel::Member; - for rank in ranks.into_iter() { + for rank in ranks { if rank > max { max = rank } diff --git a/src/client/server/mod.rs b/src/client/server/mod.rs index 4cb5580..37cb71d 100644 --- a/src/client/server/mod.rs +++ b/src/client/server/mod.rs @@ -6,6 +6,7 @@ use std::error::Error as StdError; use std::io::{Error, ErrorKind, Result}; use std::path::Path; use std::sync::{Arc, Mutex, RwLock}; +use std::sync::atomic::{AtomicBool, Ordering}; use std::thread::{spawn, sleep}; use std::time::Duration as StdDuration; use client::conn::{Connection, NetConnection}; @@ -61,7 +62,7 @@ struct ServerState { /// A thread-safe store for the last ping data. last_ping_data: Mutex>, /// A thread-safe check of pong reply. - waiting_pong_reply: Mutex, + waiting_pong_reply: AtomicBool, } impl ServerState { @@ -74,15 +75,14 @@ impl ServerState { reconnect_count: Mutex::new(0), last_action_time: Mutex::new(now()), last_ping_data: Mutex::new(None), - waiting_pong_reply: Mutex::new(false), + waiting_pong_reply: AtomicBool::new(false), } } fn reconnect(&self) -> Result<()> { let mut ping_data = self.last_ping_data.lock().unwrap(); *ping_data = None; - let mut waiting_pong_reply = self.waiting_pong_reply.lock().unwrap(); - *waiting_pong_reply = false; + self.waiting_pong_reply.store(false, Ordering::SeqCst); self.conn.reconnect() } @@ -103,8 +103,7 @@ impl ServerState { fn update_ping_data(&self, data: Timespec) { let mut ping_data = self.last_ping_data.lock().unwrap(); *ping_data = Some(data); - let mut waiting_pong_reply = self.waiting_pong_reply.lock().unwrap(); - *waiting_pong_reply = true; + self.waiting_pong_reply.store(true, Ordering::SeqCst); } fn last_ping_data(&self) -> Option { @@ -112,7 +111,7 @@ impl ServerState { } fn waiting_pong_reply(&self) -> bool { - *self.waiting_pong_reply.lock().unwrap() + self.waiting_pong_reply.load(Ordering::SeqCst) } fn check_pong(&self, data: &str) { @@ -120,8 +119,7 @@ impl ServerState { let fmt = format!("{}", time.sec); if fmt == data { // found matching pong reply - let mut waiting_reply = self.waiting_pong_reply.lock().unwrap(); - *waiting_reply = false; + self.waiting_pong_reply.store(false, Ordering::SeqCst); } } } @@ -364,9 +362,8 @@ impl IrcServer { /// Handles received messages internally for basic client functionality. fn handle_message(&self, msg: &Message) -> Result<()> { match msg.command { - PING(ref data, _) => try!(self.send_pong(&data)), - PONG(_, Some(ref pingdata)) => self.state.check_pong(&pingdata), - PONG(ref pingdata, None) => self.state.check_pong(&pingdata), + PING(ref data, _) => try!(self.send_pong(data)), + PONG(ref pingdata, None) | PONG(_, Some(ref pingdata)) => self.state.check_pong(pingdata), JOIN(ref chan, _, _) => self.handle_join(msg.source_nickname().unwrap_or(""), chan), PART(ref chan, _) => self.handle_part(msg.source_nickname().unwrap_or(""), chan), QUIT(_) => self.handle_quit(msg.source_nickname().unwrap_or("")), @@ -382,7 +379,7 @@ impl IrcServer { body[1..end].split(' ').collect() }; if target.starts_with('#') { - try!(self.handle_ctcp(&target, tokens)) + try!(self.handle_ctcp(target, tokens)) } else if let Some(user) = msg.source_nickname() { try!(self.handle_ctcp(user, tokens)) } @@ -396,7 +393,7 @@ impl IrcServer { try!(self.send_umodes()); let config_chans = self.config().channels(); - for chan in config_chans.iter() { + for chan in &config_chans { match self.config().channel_key(chan) { Some(key) => try!(self.send_join_with_keys(chan, key)), None => try!(self.send_join(chan)) @@ -501,9 +498,9 @@ impl IrcServer { let mut chanlists = self.chanlists().lock().unwrap(); for channel in chanlists.clone().keys() { if let Some(vec) = chanlists.get_mut(&channel.to_owned()) { - for p in vec.iter().position(|x| x.get_nickname() == old_nick) { + if let Some(n) = vec.iter().position(|x| x.get_nickname() == old_nick) { let new_entry = User::new(new_nick); - vec[p] = new_entry; + vec[n] = new_entry; } } } @@ -516,7 +513,7 @@ impl IrcServer { fn handle_mode(&self, chan: &str, mode: &str, user: &str) { if let Some(vec) = self.chanlists().lock().unwrap().get_mut(chan) { if let Some(n) = vec.iter().position(|x| x.get_nickname() == user) { - vec[n].update_access_level(&mode) + vec[n].update_access_level(mode) } } } @@ -541,7 +538,7 @@ impl IrcServer { /// Handles CTCP requests if the CTCP feature is enabled. #[cfg(feature = "ctcp")] fn handle_ctcp(&self, resp: &str, tokens: Vec<&str>) -> Result<()> { - if tokens.len() == 0 { return Ok(()) } + if tokens.is_empty() { return Ok(()) } match tokens[0] { "FINGER" => self.send_ctcp_internal(resp, &format!( "FINGER :{} ({})", self.config().real_name(), self.config().username() @@ -579,7 +576,7 @@ impl IrcServer { } } -/// An Iterator over an IrcServer's incoming Messages. +/// An `Iterator` over an `IrcServer`'s incoming `Messages`. pub struct ServerIterator<'a> { server: &'a IrcServer }