From 71e1df7063d07a2f1f93e29ea9a7b67874fb021e Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sun, 2 Jun 2019 09:40:00 -0700 Subject: [PATCH] Add clippy lints. --- src/error.rs | 14 ++++++++------ src/lib.rs | 39 ++++++++++++++++++++++++++++++++------- src/session.rs | 4 +++- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/error.rs b/src/error.rs index f6ca9384..b1c6ee9e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,3 +1,5 @@ +//! Error conditions. + use http::uri::InvalidUri; use hyper::error::Error as HyperError; use ruma_api::Error as RumaApiError; @@ -25,37 +27,37 @@ pub enum Error { } impl From for Error { - fn from(error: HyperError) -> Error { + fn from(error: HyperError) -> Self { Error::Hyper(error) } } impl From for Error { - fn from(error: InvalidUri) -> Error { + fn from(error: InvalidUri) -> Self { Error::Uri(error) } } impl From for Error { - fn from(error: ParseError) -> Error { + fn from(error: ParseError) -> Self { Error::Url(error) } } impl From for Error { - fn from(error: RumaApiError) -> Error { + fn from(error: RumaApiError) -> Self { Error::RumaApi(error) } } impl From for Error { - fn from(error: SerdeJsonError) -> Error { + fn from(error: SerdeJsonError) -> Self { Error::SerdeJson(error) } } impl From for Error { - fn from(error: SerdeUrlEncodedSerializeError) -> Error { + fn from(error: SerdeUrlEncodedSerializeError) -> Self { Error::SerdeUrlEncodedSerialize(error) } } diff --git a/src/lib.rs b/src/lib.rs index 55882271..f65274b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,29 @@ //! Crate `ruma_client` is a [Matrix](https://matrix.org/) client library. -#![deny(missing_debug_implementations)] -#![deny(missing_docs)] +#![deny( + missing_copy_implementations, + missing_debug_implementations, + missing_docs, + warnings +)] +#![warn( + clippy::empty_line_after_outer_attr, + clippy::expl_impl_clone_on_copy, + clippy::if_not_else, + clippy::items_after_statements, + clippy::match_same_arms, + clippy::mem_forget, + clippy::missing_docs_in_private_items, + clippy::mut_mut, + clippy::needless_borrow, + clippy::needless_continue, + clippy::single_match_else, + clippy::unicode_not_nfc, + clippy::use_self, + clippy::used_underscore_binding, + clippy::wrong_pub_self_convention, + clippy::wrong_self_convention +)] use std::{ convert::TryInto, @@ -41,15 +63,18 @@ struct ClientData where C: Connect, { + /// The URL of the homeserver to connect to. homeserver_url: Url, + /// The underlying HTTP client. hyper: HyperClient, + /// User session data. session: Mutex>, } impl Client { /// Creates a new client for making HTTP requests to the given homeserver. pub fn new(homeserver_url: Url, session: Option) -> Self { - Client(Arc::new(ClientData { + Self(Arc::new(ClientData { homeserver_url, hyper: HyperClient::builder().keep_alive(true).build_http(), session: Mutex::new(session), @@ -63,7 +88,7 @@ impl Client> { pub fn https(homeserver_url: Url, session: Option) -> Result { let connector = HttpsConnector::new(4)?; - Ok(Client(Arc::new(ClientData { + Ok(Self(Arc::new(ClientData { homeserver_url, hyper: { HyperClient::builder().keep_alive(true).build(connector) }, session: Mutex::new(session), @@ -83,7 +108,7 @@ where homeserver_url: Url, session: Option, ) -> Self { - Client(Arc::new(ClientData { + Self(Arc::new(ClientData { homeserver_url, hyper: hyper_client, session: Mutex::new(session), @@ -290,7 +315,7 @@ where } impl Clone for Client { - fn clone(&self) -> Client { - Client(self.0.clone()) + fn clone(&self) -> Self { + Self(self.0.clone()) } } diff --git a/src/session.rs b/src/session.rs index b22809df..331baeb7 100644 --- a/src/session.rs +++ b/src/session.rs @@ -1,3 +1,5 @@ +//! User sessions. + use ruma_identifiers::UserId; /// A user session, containing an access token and information about the associated user account. @@ -15,7 +17,7 @@ impl Session { /// Create a new user session from an access token and a user ID. #[deprecated] pub fn new(access_token: String, user_id: UserId, device_id: String) -> Self { - Session { + Self { access_token, user_id, device_id,