Cleaned up a bunch of code with clippy.

This commit is contained in:
Aaron Weiss 2018-01-28 01:14:55 +01:00
parent 90276b63b0
commit afe3558880
No known key found for this signature in database
GPG key ID: 047D32DF25DC22EF
8 changed files with 29 additions and 33 deletions

View file

@ -80,19 +80,19 @@ impl<'a> Future for ConnectionFuture<'a> {
fn poll(&mut self) -> Poll<Self::Item, Self::Error> { fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
match *self { match *self {
ConnectionFuture::Unsecured(ref config, ref mut inner) => { ConnectionFuture::Unsecured(config, ref mut inner) => {
let framed = try_ready!(inner.poll()).framed(IrcCodec::new(config.encoding())?); let framed = try_ready!(inner.poll()).framed(IrcCodec::new(config.encoding())?);
let transport = IrcTransport::new(config, framed); let transport = IrcTransport::new(config, framed);
Ok(Async::Ready(Connection::Unsecured(transport))) Ok(Async::Ready(Connection::Unsecured(transport)))
} }
ConnectionFuture::Secured(ref config, ref mut inner) => { ConnectionFuture::Secured(config, ref mut inner) => {
let framed = try_ready!(inner.poll()).framed(IrcCodec::new(config.encoding())?); let framed = try_ready!(inner.poll()).framed(IrcCodec::new(config.encoding())?);
let transport = IrcTransport::new(config, framed); let transport = IrcTransport::new(config, framed);
Ok(Async::Ready(Connection::Secured(transport))) Ok(Async::Ready(Connection::Secured(transport)))
} }
ConnectionFuture::Mock(ref config) => { ConnectionFuture::Mock(config) => {
let enc: error::Result<_> = encoding_from_whatwg_label( let enc: error::Result<_> = encoding_from_whatwg_label(
config.encoding() config.encoding()
).ok_or_else(|| io::Error::new( ).ok_or_else(|| io::Error::new(

View file

@ -38,7 +38,7 @@ use proto::Message;
/// all connected servers as the application runs. It can be used to run multiple servers on the /// all connected servers as the application runs. It can be used to run multiple servers on the
/// same thread, as well as to get better control over error management in an IRC client. /// same thread, as well as to get better control over error management in an IRC client.
/// ///
/// For a full example usage, see [irc::client::reactor](./index.html). /// For a full example usage, see [`irc::client::reactor`](./index.html).
pub struct IrcReactor { pub struct IrcReactor {
inner: Core, inner: Core,
handlers: Vec<Box<Future<Item = (), Error = error::Error>>>, handlers: Vec<Box<Future<Item = (), Error = error::Error>>>,

View file

@ -1,11 +1,11 @@
//! The primary API for communicating with an IRC server. //! The primary API for communicating with an IRC server.
//! //!
//! This API provides the ability to connect to an IRC server via the //! This API provides the ability to connect to an IRC server via the
//! [IrcServer](struct.IrcServer.html) type. The [Server](trait.Server.html) trait that //! [`IrcServer`](struct.IrcServer.html) type. The [`Server`](trait.Server.html) trait that
//! [IrcServer](struct.IrcServer.html) implements provides methods for communicating with this //! [`IrcServer`](struct.IrcServer.html) implements provides methods for communicating with this
//! server. An extension trait, [ServerExt](./utils/trait.ServerExt.html), provides short-hand for //! server. An extension trait, [`ServerExt`](./utils/trait.ServerExt.html), provides short-hand for
//! sending a variety of important messages without referring to their entries in //! sending a variety of important messages without referring to their entries in
//! [proto::command](../../proto/command/enum.Command.html). //! [`proto::command`](../../proto/command/enum.Command.html).
//! //!
//! # Examples //! # Examples
//! //!
@ -45,8 +45,6 @@
//! }).unwrap(); //! }).unwrap();
//! # } //! # }
//! ``` //! ```
#[cfg(feature = "ctcp")]
use std::ascii::AsciiExt;
use std::collections::HashMap; use std::collections::HashMap;
use std::path::Path; use std::path::Path;
use std::sync::{Arc, Mutex, RwLock}; use std::sync::{Arc, Mutex, RwLock};
@ -73,9 +71,9 @@ pub mod utils;
/// Trait extending all IRC streams with `for_each_incoming` convenience function. /// Trait extending all IRC streams with `for_each_incoming` convenience function.
/// ///
/// This is typically used in conjunction with [Server::stream](trait.Server.html#tymethod.stream) /// This is typically used in conjunction with [`Server::stream`](trait.Server.html#tymethod.stream)
/// in order to use an API akin to /// in order to use an API akin to
/// [Server::for_each_incoming](trait.Server.html#method.for_each_incoming). /// [`Server::for_each_incoming`](trait.Server.html#method.for_each_incoming).
/// ///
/// # Example /// # Example
/// ///
@ -352,7 +350,6 @@ impl ServerState {
trace!("[RECV] {}", msg.to_string()); trace!("[RECV] {}", msg.to_string());
match msg.command { match msg.command {
JOIN(ref chan, _, _) => self.handle_join(msg.source_nickname().unwrap_or(""), chan), JOIN(ref chan, _, _) => self.handle_join(msg.source_nickname().unwrap_or(""), chan),
/// This will panic if not specified.
PART(ref chan, _) => self.handle_part(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("")), QUIT(_) => self.handle_quit(msg.source_nickname().unwrap_or("")),
NICK(ref new_nick) => { NICK(ref new_nick) => {
@ -595,12 +592,12 @@ impl ServerState {
/// ///
/// The type itself provides a number of methods to create new connections, but most of the API /// The type itself provides a number of methods to create new connections, but most of the API
/// surface is in the form of the [Server](trait.Server.html) and /// surface is in the form of the [Server](trait.Server.html) and
/// [ServerExt](./utils/trait.ServerExt.html) traits that provide methods of communicating with the /// [`ServerExt`](./utils/trait.ServerExt.html) traits that provide methods of communicating with
/// server after connection. Cloning an `IrcServer` is relatively cheap, as it's equivalent to /// the server after connection. Cloning an `IrcServer` is relatively cheap, as it's equivalent to
/// cloning a single `Arc`. This may be useful for setting up multiple threads with access to one /// cloning a single `Arc`. This may be useful for setting up multiple threads with access to one
/// connection. /// connection.
/// ///
/// For a full example usage, see [irc::client::server](./index.html). /// For a full example usage, see [`irc::client::server`](./index.html).
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct IrcServer { pub struct IrcServer {
/// The internal, thread-safe server state. /// The internal, thread-safe server state.
@ -748,7 +745,7 @@ impl IrcServer {
/// [futures](http://docs.rs/futures). Additionally, you can find detailed tutorials on using /// [futures](http://docs.rs/futures). Additionally, you can find detailed tutorials on using
/// both libraries on the [tokio website](https://tokio.rs/docs/getting-started/tokio/). An easy /// both libraries on the [tokio website](https://tokio.rs/docs/getting-started/tokio/). An easy
/// to use abstraction that does not require this knowledge is available via /// to use abstraction that does not require this knowledge is available via
/// [IrcReactors](../reactor/struct.IrcReactor.html). /// [`IrcReactors`](../reactor/struct.IrcReactor.html).
/// ///
/// # Example /// # Example
/// ```no_run /// ```no_run
@ -809,7 +806,7 @@ impl IrcServer {
/// use cases. To learn more, you can view the documentation for the /// use cases. To learn more, you can view the documentation for the
/// [futures](https://docs.rs/futures/) crate, or the tutorials for /// [futures](https://docs.rs/futures/) crate, or the tutorials for
/// [tokio](https://tokio.rs/docs/getting-started/futures/). An easy to use abstraction that does /// [tokio](https://tokio.rs/docs/getting-started/futures/). An easy to use abstraction that does
/// not require this knowledge is available via [IrcReactors](../reactor/struct.IrcReactor.html). /// not require this knowledge is available via [`IrcReactors`](../reactor/struct.IrcReactor.html).
#[derive(Debug)] #[derive(Debug)]
pub struct IrcServerFuture<'a> { pub struct IrcServerFuture<'a> {
conn: ConnectionFuture<'a>, conn: ConnectionFuture<'a>,
@ -849,7 +846,7 @@ impl<'a> Future for IrcServerFuture<'a> {
/// ///
/// This type should only be used by advanced users who are familiar with the implementation of this /// This type should only be used by advanced users who are familiar with the implementation of this
/// crate. An easy to use abstraction that does not require this knowledge is available via /// crate. An easy to use abstraction that does not require this knowledge is available via
/// [IrcReactors](../reactor/struct.IrcReactor.html). /// [`IrcReactors`](../reactor/struct.IrcReactor.html).
pub struct PackedIrcServer(pub IrcServer, pub Box<Future<Item = (), Error = error::Error>>); pub struct PackedIrcServer(pub IrcServer, pub Box<Future<Item = (), Error = error::Error>>);
#[cfg(test)] #[cfg(test)]

View file

@ -1,12 +1,12 @@
//! Utilities and shortcuts for working with IRC servers. //! Utilities and shortcuts for working with IRC servers.
//! //!
//! This module provides the [ServerExt](trait.ServerExt.html) trait which is the idiomatic way of //! This module provides the [`ServerExt`](trait.ServerExt.html) trait which is the idiomatic way of
//! sending messages to an IRC server. This trait is automatically implemented for everything that //! sending messages to an IRC server. This trait is automatically implemented for everything that
//! implements [Server](../trait.Server.html) and is designed to provide important functionality //! implements [`Server`](../trait.Server.html) and is designed to provide important functionality
//! without clutter. //! without clutter.
//! //!
//! # Examples //! # Examples
//! //!
//! Using these APIs, we can connect to a server and send a one-off message (in this case, //! Using these APIs, we can connect to a server and send a one-off message (in this case,
//! identifying with the server). //! identifying with the server).
//! //!
@ -15,7 +15,7 @@
//! use irc::client::prelude::{IrcServer, ServerExt}; //! use irc::client::prelude::{IrcServer, ServerExt};
//! //!
//! # fn main() { //! # fn main() {
//! let server = IrcServer::new("config.toml").unwrap(); //! let server = IrcServer::new("config.toml").unwrap();
//! // identify and send_privmsg both come from `ServerExt` //! // identify and send_privmsg both come from `ServerExt`
//! server.identify().unwrap(); //! server.identify().unwrap();
//! server.send_privmsg("#example", "Hello, world!").unwrap(); //! server.send_privmsg("#example", "Hello, world!").unwrap();

View file

@ -44,11 +44,11 @@ where
inner: inner, inner: inner,
burst_timer: tokio_timer::wheel().build(), burst_timer: tokio_timer::wheel().build(),
rolling_burst_window: VecDeque::new(), rolling_burst_window: VecDeque::new(),
burst_window_length: config.burst_window_length() as u64, burst_window_length: u64::from(config.burst_window_length()),
max_burst_messages: config.max_messages_in_burst() as u64, max_burst_messages: u64::from(config.max_messages_in_burst()),
current_burst_messages: 0, current_burst_messages: 0,
ping_timer: timer.interval(Duration::from_secs(config.ping_time() as u64)), ping_timer: timer.interval(Duration::from_secs(u64::from(config.ping_time()))),
ping_timeout: config.ping_timeout() as u64, ping_timeout: u64::from(config.ping_timeout()),
last_ping_data: String::new(), last_ping_data: String::new(),
last_ping_sent: Instant::now(), last_ping_sent: Instant::now(),
last_pong_received: Instant::now(), last_pong_received: Instant::now(),

View file

@ -1,7 +1,7 @@
//! A simple, thread-safe, and async-friendly library for IRC clients. //! A simple, thread-safe, and async-friendly library for IRC clients.
//! //!
//! # Quick Start //! # Quick Start
//! The main public API is entirely exported in [client::prelude](./client/prelude/index.html). This //! The main public API is entirely exported in [`client::prelude`](./client/prelude/index.html). This
//! should include everything necessary to write an IRC client or bot. //! should include everything necessary to write an IRC client or bot.
//! //!
//! # A Whirlwind Tour //! # A Whirlwind Tour
@ -11,7 +11,7 @@
//! implementation that could in principle be used in either client or server software. Both modules //! implementation that could in principle be used in either client or server software. Both modules
//! feature a number of components that are low-level and can be used to build alternative APIs for //! feature a number of components that are low-level and can be used to build alternative APIs for
//! the IRC protocol. For the average user, the higher-level components for an IRC client are all //! the IRC protocol. For the average user, the higher-level components for an IRC client are all
//! re-exported in [client::prelude](./client/prelude/index.html). That module serves as the best //! re-exported in [`client::prelude`](./client/prelude/index.html). That module serves as the best
//! starting point for a new user trying to understand the high-level API. //! starting point for a new user trying to understand the high-level API.
//! //!
//! # Example //! # Example
@ -72,7 +72,7 @@ pub mod client;
pub mod error; pub mod error;
pub mod proto; pub mod proto;
const VERSION_STR: &'static str = concat!( const VERSION_STR: &str = concat!(
env!("CARGO_PKG_NAME"), env!("CARGO_PKG_NAME"),
":", ":",
env!("CARGO_PKG_VERSION"), env!("CARGO_PKG_VERSION"),

View file

@ -1,5 +1,4 @@
//! Enumeration of all available client commands. //! Enumeration of all available client commands.
use std::ascii::AsciiExt;
use std::str::FromStr; use std::str::FromStr;
use error; use error;

View file

@ -85,7 +85,7 @@ impl Message {
s.find('@'), s.find('@'),
s.find('.'), s.find('.'),
) { ) {
(Some(i), _, _) => Some(&s[..i]), // <nick> '!' <user> [ '@' <host> ] (Some(i), _, _) | // <nick> '!' <user> [ '@' <host> ]
(None, Some(i), _) => Some(&s[..i]), // <nick> '@' <host> (None, Some(i), _) => Some(&s[..i]), // <nick> '@' <host>
(None, None, None) => Some(s), // <nick> (None, None, None) => Some(s), // <nick>
_ => None, // <servername> _ => None, // <servername>
@ -223,7 +223,7 @@ impl FromStr for Message {
cmd cmd
} }
// If there's no arguments but the "command" starts with colon, it's not a command. // If there's no arguments but the "command" starts with colon, it's not a command.
None if state.starts_with(":") => return Err(ErrorKind::InvalidCommand.into()), None if state.starts_with(':') => return Err(ErrorKind::InvalidCommand.into()),
// If there's no arguments following the command, the rest of the state is the command. // If there's no arguments following the command, the rest of the state is the command.
None => { None => {
let cmd = state; let cmd = state;