From afe3558880e0d4c66be51552e3908a6184ade1a5 Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Sun, 28 Jan 2018 01:14:55 +0100 Subject: [PATCH] Cleaned up a bunch of code with clippy. --- src/client/conn.rs | 6 +++--- src/client/reactor.rs | 2 +- src/client/server/mod.rs | 27 ++++++++++++--------------- src/client/server/utils.rs | 8 ++++---- src/client/transport.rs | 8 ++++---- src/lib.rs | 6 +++--- src/proto/command.rs | 1 - src/proto/message.rs | 4 ++-- 8 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/client/conn.rs b/src/client/conn.rs index 8dbdc0e..dbe7f5e 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -80,19 +80,19 @@ impl<'a> Future for ConnectionFuture<'a> { fn poll(&mut self) -> Poll { 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 transport = IrcTransport::new(config, framed); 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 transport = IrcTransport::new(config, framed); Ok(Async::Ready(Connection::Secured(transport))) } - ConnectionFuture::Mock(ref config) => { + ConnectionFuture::Mock(config) => { let enc: error::Result<_> = encoding_from_whatwg_label( config.encoding() ).ok_or_else(|| io::Error::new( diff --git a/src/client/reactor.rs b/src/client/reactor.rs index dca3fe9..b6b995c 100644 --- a/src/client/reactor.rs +++ b/src/client/reactor.rs @@ -38,7 +38,7 @@ use proto::Message; /// 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. /// -/// 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 { inner: Core, handlers: Vec>>, diff --git a/src/client/server/mod.rs b/src/client/server/mod.rs index 5d09319..eeb8f06 100644 --- a/src/client/server/mod.rs +++ b/src/client/server/mod.rs @@ -1,11 +1,11 @@ //! The primary API for communicating with an IRC server. //! //! 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) implements provides methods for communicating with this -//! server. An extension trait, [ServerExt](./utils/trait.ServerExt.html), provides short-hand for +//! [`IrcServer`](struct.IrcServer.html) type. The [`Server`](trait.Server.html) trait that +//! [`IrcServer`](struct.IrcServer.html) implements provides methods for communicating with this +//! 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 -//! [proto::command](../../proto/command/enum.Command.html). +//! [`proto::command`](../../proto/command/enum.Command.html). //! //! # Examples //! @@ -45,8 +45,6 @@ //! }).unwrap(); //! # } //! ``` -#[cfg(feature = "ctcp")] -use std::ascii::AsciiExt; use std::collections::HashMap; use std::path::Path; use std::sync::{Arc, Mutex, RwLock}; @@ -73,9 +71,9 @@ pub mod utils; /// 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 -/// [Server::for_each_incoming](trait.Server.html#method.for_each_incoming). +/// [`Server::for_each_incoming`](trait.Server.html#method.for_each_incoming). /// /// # Example /// @@ -352,7 +350,6 @@ impl ServerState { trace!("[RECV] {}", msg.to_string()); match msg.command { 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), QUIT(_) => self.handle_quit(msg.source_nickname().unwrap_or("")), 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 /// 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 -/// server after connection. Cloning an `IrcServer` is relatively cheap, as it's equivalent to +/// [`ServerExt`](./utils/trait.ServerExt.html) traits that provide methods of communicating with +/// 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 /// 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)] pub struct IrcServer { /// 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 /// 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 - /// [IrcReactors](../reactor/struct.IrcReactor.html). + /// [`IrcReactors`](../reactor/struct.IrcReactor.html). /// /// # Example /// ```no_run @@ -809,7 +806,7 @@ impl IrcServer { /// use cases. To learn more, you can view the documentation for the /// [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 -/// 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)] pub struct IrcServerFuture<'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 /// 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>); #[cfg(test)] diff --git a/src/client/server/utils.rs b/src/client/server/utils.rs index 8105c19..2ee3e4f 100644 --- a/src/client/server/utils.rs +++ b/src/client/server/utils.rs @@ -1,12 +1,12 @@ //! 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 -//! 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. //! //! # Examples -//! +//! //! Using these APIs, we can connect to a server and send a one-off message (in this case, //! identifying with the server). //! @@ -15,7 +15,7 @@ //! use irc::client::prelude::{IrcServer, ServerExt}; //! //! # fn main() { -//! let server = IrcServer::new("config.toml").unwrap(); +//! let server = IrcServer::new("config.toml").unwrap(); //! // identify and send_privmsg both come from `ServerExt` //! server.identify().unwrap(); //! server.send_privmsg("#example", "Hello, world!").unwrap(); diff --git a/src/client/transport.rs b/src/client/transport.rs index ca52c91..08fbd79 100644 --- a/src/client/transport.rs +++ b/src/client/transport.rs @@ -44,11 +44,11 @@ where inner: inner, burst_timer: tokio_timer::wheel().build(), rolling_burst_window: VecDeque::new(), - burst_window_length: config.burst_window_length() as u64, - max_burst_messages: config.max_messages_in_burst() as u64, + burst_window_length: u64::from(config.burst_window_length()), + max_burst_messages: u64::from(config.max_messages_in_burst()), current_burst_messages: 0, - ping_timer: timer.interval(Duration::from_secs(config.ping_time() as u64)), - ping_timeout: config.ping_timeout() as u64, + ping_timer: timer.interval(Duration::from_secs(u64::from(config.ping_time()))), + ping_timeout: u64::from(config.ping_timeout()), last_ping_data: String::new(), last_ping_sent: Instant::now(), last_pong_received: Instant::now(), diff --git a/src/lib.rs b/src/lib.rs index 0fbff4c..3b85507 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ //! A simple, thread-safe, and async-friendly library for IRC clients. //! //! # 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. //! //! # A Whirlwind Tour @@ -11,7 +11,7 @@ //! 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 //! 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. //! //! # Example @@ -72,7 +72,7 @@ pub mod client; pub mod error; pub mod proto; -const VERSION_STR: &'static str = concat!( +const VERSION_STR: &str = concat!( env!("CARGO_PKG_NAME"), ":", env!("CARGO_PKG_VERSION"), diff --git a/src/proto/command.rs b/src/proto/command.rs index 3737f3c..e11b9c8 100644 --- a/src/proto/command.rs +++ b/src/proto/command.rs @@ -1,5 +1,4 @@ //! Enumeration of all available client commands. -use std::ascii::AsciiExt; use std::str::FromStr; use error; diff --git a/src/proto/message.rs b/src/proto/message.rs index 8605cc2..a7c0338 100644 --- a/src/proto/message.rs +++ b/src/proto/message.rs @@ -85,7 +85,7 @@ impl Message { s.find('@'), s.find('.'), ) { - (Some(i), _, _) => Some(&s[..i]), // '!' [ '@' ] + (Some(i), _, _) | // '!' [ '@' ] (None, Some(i), _) => Some(&s[..i]), // '@' (None, None, None) => Some(s), // _ => None, // @@ -223,7 +223,7 @@ impl FromStr for Message { cmd } // 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. None => { let cmd = state;