From 388bf8b49c72d4f79478b7767541f9ef7c497da2 Mon Sep 17 00:00:00 2001 From: Dominic Date: Fri, 1 Jan 2021 18:03:31 +0100 Subject: [PATCH] apply some clippy suggestions --- src/cors.rs | 5 ++++- src/lib.rs | 7 ++++++- src/response.rs | 4 ++++ src/result/mod.rs | 2 +- src/result/raw.rs | 2 +- src/result/result.rs | 2 +- src/result/success.rs | 2 +- src/routing.rs | 7 +++++-- 8 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/cors.rs b/src/cors.rs index d8f2988..7f1fc31 100644 --- a/src/cors.rs +++ b/src/cors.rs @@ -11,7 +11,10 @@ use gotham::{ }, middleware::Middleware, pipeline::chain::PipelineHandleChain, - router::{builder::*, route::matcher::AccessControlRequestMethodMatcher}, + router::{ + builder::{DefineSingleRoute, DrawRoutes, ExtendRouteMatcher}, + route::matcher::AccessControlRequestMethodMatcher + }, state::{FromState, State} }; use std::{panic::RefUnwindSafe, pin::Pin}; diff --git a/src/lib.rs b/src/lib.rs index 0ca5549..24e8297 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,10 @@ #![allow(clippy::tabs_in_doc_comments)] -#![warn(missing_debug_implementations, rust_2018_idioms)] +#![warn( + missing_debug_implementations, + rust_2018_idioms, + clippy::wildcard_imports, + clippy::redundant_closure_for_method_calls +)] #![deny(broken_intra_doc_links)] #![forbid(unsafe_code)] /*! diff --git a/src/response.rs b/src/response.rs index 5fe1d32..cc50325 100644 --- a/src/response.rs +++ b/src/response.rs @@ -11,6 +11,7 @@ pub struct Response { impl Response { /// Create a new [Response] from raw data. + #[must_use = "Creating a response is pointless if you don't use it"] pub fn new>(status: StatusCode, body: B, mime: Option) -> Self { Self { status, @@ -20,6 +21,7 @@ impl Response { } /// Create a [Response] with mime type json from already serialized data. + #[must_use = "Creating a response is pointless if you don't use it"] pub fn json>(status: StatusCode, body: B) -> Self { Self { status, @@ -29,6 +31,7 @@ impl Response { } /// Create a _204 No Content_ [Response]. + #[must_use = "Creating a response is pointless if you don't use it"] pub fn no_content() -> Self { Self { status: StatusCode::NO_CONTENT, @@ -38,6 +41,7 @@ impl Response { } /// Create an empty _403 Forbidden_ [Response]. + #[must_use = "Creating a response is pointless if you don't use it"] pub fn forbidden() -> Self { Self { status: StatusCode::FORBIDDEN, diff --git a/src/result/mod.rs b/src/result/mod.rs index 2c79d37..526af33 100644 --- a/src/result/mod.rs +++ b/src/result/mod.rs @@ -125,7 +125,7 @@ where type Err = Res::Err; fn into_response(self) -> Pin> + Send>> { - self.then(|result| result.into_response()).boxed() + self.then(ResourceResult::into_response).boxed() } fn accepted_types() -> Option> { diff --git a/src/result/raw.rs b/src/result/raw.rs index dd174d0..6b3b520 100644 --- a/src/result/raw.rs +++ b/src/result/raw.rs @@ -92,7 +92,7 @@ where type Err = SerdeJsonError; // just for easier handling of `Result, E>` fn into_response(self) -> Pin> + Send>> { - future::ok(Response::new(StatusCode::OK, self.raw, Some(self.mime.clone()))).boxed() + future::ok(Response::new(StatusCode::OK, self.raw, Some(self.mime))).boxed() } #[cfg(feature = "openapi")] diff --git a/src/result/result.rs b/src/result/result.rs index 71c969a..f22d756 100644 --- a/src/result/result.rs +++ b/src/result/result.rs @@ -71,7 +71,7 @@ mod test { let res = block_on(ok.into_response()).expect("didn't expect error response"); assert_eq!(res.status, StatusCode::OK); assert_eq!(res.mime, Some(APPLICATION_JSON)); - assert_eq!(res.full_body().unwrap(), r#"{"msg":""}"#.as_bytes()); + assert_eq!(res.full_body().unwrap(), br#"{"msg":""}"#); } #[test] diff --git a/src/result/success.rs b/src/result/success.rs index 7ed7cf7..a3816ea 100644 --- a/src/result/success.rs +++ b/src/result/success.rs @@ -129,7 +129,7 @@ mod test { let res = block_on(success.into_response()).expect("didn't expect error response"); assert_eq!(res.status, StatusCode::OK); assert_eq!(res.mime, Some(APPLICATION_JSON)); - assert_eq!(res.full_body().unwrap(), r#"{"msg":""}"#.as_bytes()); + assert_eq!(res.full_body().unwrap(), br#"{"msg":""}"#); } #[test] diff --git a/src/routing.rs b/src/routing.rs index ea4d5dd..940a51b 100644 --- a/src/routing.rs +++ b/src/routing.rs @@ -6,7 +6,10 @@ use crate::openapi::{ #[cfg(feature = "cors")] use crate::CorsRoute; use crate::{ - resource::*, + resource::{ + Resource, ResourceChange, ResourceChangeAll, ResourceCreate, ResourceRead, ResourceReadAll, ResourceRemove, + ResourceRemoveAll, ResourceSearch + }, result::{ResourceError, ResourceResult}, RequestBody, Response, StatusCode }; @@ -18,7 +21,7 @@ use gotham::{ hyper::{body::to_bytes, header::CONTENT_TYPE, Body, HeaderMap, Method}, pipeline::chain::PipelineHandleChain, router::{ - builder::*, + builder::{DefineSingleRoute, DrawRoutes, ExtendRouteMatcher, RouterBuilder, ScopeBuilder}, non_match::RouteNonMatch, route::matcher::{AcceptHeaderRouteMatcher, ContentTypeHeaderRouteMatcher, RouteMatcher} },