Applied a bunch of clippy lints.

This commit is contained in:
Aaron Weiss 2017-06-19 13:46:01 -04:00
parent c4888ed76c
commit 388628d62a
No known key found for this signature in database
GPG key ID: 0237035D9BF03AE2
10 changed files with 168 additions and 171 deletions

View file

@ -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();

View file

@ -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();

View file

@ -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()

View file

@ -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();

View file

@ -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<NetStream>;
type NetWriter = BufWriter<NetStream>;
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<String>,
port: Mutex<u16>,
@ -105,7 +105,7 @@ impl NetConnection {
}
}
/// Converts a Result<T, SslError> into an Result<T>.
/// Converts a `Result<T, SslError>` into an `io::Result<T>`.
#[cfg(feature = "ssl")]
fn ssl_to_io<T>(res: StdResult<T, SslError>) -> Result<T> {
match res {

View file

@ -175,7 +175,7 @@ pub enum Command {
Raw(String, Vec<String>, Option<String>),
}
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::<Vec<_>>(), None),
Command::ISON(ref u) => stringify("ISON", &u.iter().map(|s| &s[..]).collect::<Vec<_>>(), 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::<Vec<_>>(),
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::<Vec<_>>(),
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::<Vec<_>>(), 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::<Vec<_>>(), 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::<Vec<_>>(),
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::<Vec<_>>(), 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::<Vec<_>>(), 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::<Vec<_>>(), 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::<Vec<_>>(), 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::<Vec<_>>(), 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,
}
}
}

View file

@ -41,7 +41,7 @@ impl Message {
match (s.find('!'), s.find('@'), s.find('.')) {
(Some(i), _, _) => Some(&s[..i]), // <nick> '!' <user> [ '@' <host> ]
(None, Some(i), _) => Some(&s[..i]), // <nick> '@' <host>
(None, None, None) => Some(&s), // <nick>
(None, None, None) => Some(s), // <nick>
_ => None // <servername>
}
)
@ -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);

View file

@ -28,15 +28,15 @@ macro_rules! make_response {
make_response! {
// Expected replies
/// `001 Welcome to the Internet Relay Network <nick>!<user>@<host>`
RPL_WELCOME = 001,
RPL_WELCOME = 1,
/// `002 Your host is <servername>, running version <ver>`
RPL_YOURHOST = 002,
RPL_YOURHOST = 2,
/// `003 This server was created <date>`
RPL_CREATED = 003,
RPL_CREATED = 3,
/// `004 <servername> <version> <available user modes> available channel modes>`
RPL_MYINFO = 004,
RPL_MYINFO = 4,
/// `005 Try server <server name>, port <port number>`
RPL_BOUNCE = 005,
RPL_BOUNCE = 5,
/// `302 :*1<reply> *( " " <reply> )`
RPL_USERHOST = 302,
/// `303 :*1<nick> *( " " <nick> )`

View file

@ -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
}

View file

@ -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<Option<Timespec>>,
/// A thread-safe check of pong reply.
waiting_pong_reply: Mutex<bool>,
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<Timespec> {
@ -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
}