From 328ebf821e18f415a07c8fe67993ac4a2eb2a513 Mon Sep 17 00:00:00 2001 From: Dominic Date: Sun, 3 May 2020 18:21:50 +0200 Subject: [PATCH] some minor improvements --- .gitlab-ci.yml | 2 +- example/src/main.rs | 2 +- gotham_restful/src/auth.rs | 9 ++++++++- gotham_restful/src/lib.rs | 2 ++ gotham_restful/src/matcher/accept.rs | 2 +- gotham_restful/src/matcher/content_type.rs | 2 +- gotham_restful/src/matcher/mod.rs | 16 +++++++--------- gotham_restful/src/openapi/router.rs | 1 + gotham_restful/src/response.rs | 1 + gotham_restful/src/result/auth_result.rs | 4 ++-- gotham_restful/src/result/mod.rs | 1 + gotham_restful/src/result/no_content.rs | 2 +- gotham_restful/src/routing.rs | 4 ++-- 13 files changed, 29 insertions(+), 19 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1d4bf0e..18413f8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,7 +26,7 @@ test-all: - cargo -V script: - cargo test --workspace --all-features --doc - - cargo tarpaulin --all --all-features --exclude-files 'cargo/*' --exclude-files 'gotham_restful_derive/*' --exclude-files 'example/*' --ignore-panics --ignore-tests --out Html -v + - cargo tarpaulin --target-dir target/tarpaulin --all --all-features --exclude-files 'cargo/*' --exclude-files 'gotham_restful_derive/*' --exclude-files 'example/*' --ignore-panics --ignore-tests --out Html -v artifacts: paths: - tarpaulin-report.html diff --git a/example/src/main.rs b/example/src/main.rs index 73d892c..d062710 100644 --- a/example/src/main.rs +++ b/example/src/main.rs @@ -92,7 +92,7 @@ fn delete(id : u64) fn auth_read_all(auth : AuthStatus<()>) -> AuthSuccess { match auth { - AuthStatus::Authenticated(data) => Ok(format!("{:?}", data).into()), + AuthStatus::Authenticated(data) => Ok(format!("{:?}", data)), _ => Err(Forbidden) } } diff --git a/gotham_restful/src/auth.rs b/gotham_restful/src/auth.rs index 94c95fd..c109f07 100644 --- a/gotham_restful/src/auth.rs +++ b/gotham_restful/src/auth.rs @@ -52,8 +52,14 @@ where } } +impl Copy for AuthStatus +where + T : Copy + Send + 'static +{ +} + /// The source of the authentication token in the request. -#[derive(Clone, StateData)] +#[derive(Clone, Debug, StateData)] pub enum AuthSource { /// Take the token from a cookie with the given name. @@ -155,6 +161,7 @@ fn main() { } ``` */ +#[derive(Debug)] pub struct AuthMiddleware { source : AuthSource, diff --git a/gotham_restful/src/lib.rs b/gotham_restful/src/lib.rs index 6591105..c96e905 100644 --- a/gotham_restful/src/lib.rs +++ b/gotham_restful/src/lib.rs @@ -1,4 +1,6 @@ #![allow(clippy::tabs_in_doc_comments)] +#![warn(missing_debug_implementations, rust_2018_idioms)] +#![deny(intra_doc_link_resolution_failure)] /*! This crate is an extension to the popular [gotham web framework][gotham] for Rust. The idea is to have several RESTful resources that can be added to the gotham router. This crate will take care diff --git a/gotham_restful/src/matcher/accept.rs b/gotham_restful/src/matcher/accept.rs index 5c1ee4e..2e89ac2 100644 --- a/gotham_restful/src/matcher/accept.rs +++ b/gotham_restful/src/matcher/accept.rs @@ -86,7 +86,7 @@ route.post("/foo") # }); ``` */ -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct AcceptHeaderMatcher { types : Vec, diff --git a/gotham_restful/src/matcher/content_type.rs b/gotham_restful/src/matcher/content_type.rs index cb55571..d33ed1a 100644 --- a/gotham_restful/src/matcher/content_type.rs +++ b/gotham_restful/src/matcher/content_type.rs @@ -34,7 +34,7 @@ route.post("/foo") # }); ``` */ -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct ContentTypeMatcher { types : Vec, diff --git a/gotham_restful/src/matcher/mod.rs b/gotham_restful/src/matcher/mod.rs index e1029e3..4d5268e 100644 --- a/gotham_restful/src/matcher/mod.rs +++ b/gotham_restful/src/matcher/mod.rs @@ -21,17 +21,15 @@ impl LookupTableFromTypes for LookupTable { if include_stars { - types + return types .enumerate() .flat_map(|(i, mime)| vec![("*/*".to_owned(), i), (format!("{}/*", mime.type_()), i), (mime.essence_str().to_owned(), i)].into_iter()) - .into_group_map() - } - else - { - types - .enumerate() - .map(|(i, mime)| (mime.essence_str().to_owned(), i)) - .into_group_map() + .into_group_map(); } + + types + .enumerate() + .map(|(i, mime)| (mime.essence_str().to_owned(), i)) + .into_group_map() } } diff --git a/gotham_restful/src/openapi/router.rs b/gotham_restful/src/openapi/router.rs index 33f4cba..1fa3ccf 100644 --- a/gotham_restful/src/openapi/router.rs +++ b/gotham_restful/src/openapi/router.rs @@ -16,6 +16,7 @@ pub trait GetOpenapi fn get_openapi(&mut self, path : &str); } +#[derive(Debug)] pub struct OpenapiRouter<'a, D> { pub router : &'a mut D, diff --git a/gotham_restful/src/response.rs b/gotham_restful/src/response.rs index ee4e1f3..dbbf8c7 100644 --- a/gotham_restful/src/response.rs +++ b/gotham_restful/src/response.rs @@ -2,6 +2,7 @@ use gotham::hyper::{Body, StatusCode}; use mime::{Mime, APPLICATION_JSON}; /// A response, used to create the final gotham response from. +#[derive(Debug)] pub struct Response { pub status : StatusCode, diff --git a/gotham_restful/src/result/auth_result.rs b/gotham_restful/src/result/auth_result.rs index 86db9d3..b2ebbe1 100644 --- a/gotham_restful/src/result/auth_result.rs +++ b/gotham_restful/src/result/auth_result.rs @@ -8,7 +8,7 @@ combination with [`AuthSuccess`] or [`AuthResult`]. [`AuthSuccess`]: type.AuthSuccess.html [`AuthResult`]: type.AuthResult.html */ -#[derive(ResourceError)] +#[derive(Debug, Clone, Copy, ResourceError)] pub enum AuthError { #[status(FORBIDDEN)] @@ -54,7 +54,7 @@ error, or delegates to another error type. This type is best used with [`AuthRes [`AuthResult`]: type.AuthResult.html */ -#[derive(ResourceError)] +#[derive(Debug, ResourceError)] pub enum AuthErrorOrOther { #[status(UNAUTHORIZED)] diff --git a/gotham_restful/src/result/mod.rs b/gotham_restful/src/result/mod.rs index 834bf46..547ae42 100644 --- a/gotham_restful/src/result/mod.rs +++ b/gotham_restful/src/result/mod.rs @@ -20,6 +20,7 @@ pub use no_content::NoContent; mod raw; pub use raw::Raw; +//#[allow(clippy::module_inception)] mod result; pub use result::IntoResponseError; diff --git a/gotham_restful/src/result/no_content.rs b/gotham_restful/src/result/no_content.rs index f733118..0011a67 100644 --- a/gotham_restful/src/result/no_content.rs +++ b/gotham_restful/src/result/no_content.rs @@ -31,7 +31,7 @@ fn read_all(_state: &mut State) { # } ``` */ -#[derive(Clone, Copy, Default)] +#[derive(Clone, Copy, Debug, Default)] pub struct NoContent; impl From<()> for NoContent diff --git a/gotham_restful/src/routing.rs b/gotham_restful/src/routing.rs index cd8ea13..3e67e09 100644 --- a/gotham_restful/src/routing.rs +++ b/gotham_restful/src/routing.rs @@ -53,7 +53,7 @@ pub trait WithOpenapi { fn with_openapi(&mut self, info : OpenapiInfo, block : F) where - F : FnOnce(OpenapiRouter); + F : FnOnce(OpenapiRouter<'_, D>); } /// This trait adds the `resource` method to gotham's routing. It allows you to register @@ -320,7 +320,7 @@ macro_rules! implDrawResourceRoutes { { fn with_openapi(&mut self, info : OpenapiInfo, block : F) where - F : FnOnce(OpenapiRouter<$implType<'a, C, P>>) + F : FnOnce(OpenapiRouter<'_, $implType<'a, C, P>>) { let router = OpenapiRouter { router: self,