1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-02-23 04:52:28 +00:00

some minor improvements

This commit is contained in:
Dominic 2020-05-03 18:21:50 +02:00
parent 992d9be195
commit 328ebf821e
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
13 changed files with 29 additions and 19 deletions

View file

@ -26,7 +26,7 @@ test-all:
- cargo -V - cargo -V
script: script:
- cargo test --workspace --all-features --doc - 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: artifacts:
paths: paths:
- tarpaulin-report.html - tarpaulin-report.html

View file

@ -92,7 +92,7 @@ fn delete(id : u64)
fn auth_read_all(auth : AuthStatus<()>) -> AuthSuccess<String> fn auth_read_all(auth : AuthStatus<()>) -> AuthSuccess<String>
{ {
match auth { match auth {
AuthStatus::Authenticated(data) => Ok(format!("{:?}", data).into()), AuthStatus::Authenticated(data) => Ok(format!("{:?}", data)),
_ => Err(Forbidden) _ => Err(Forbidden)
} }
} }

View file

@ -52,8 +52,14 @@ where
} }
} }
impl<T> Copy for AuthStatus<T>
where
T : Copy + Send + 'static
{
}
/// The source of the authentication token in the request. /// The source of the authentication token in the request.
#[derive(Clone, StateData)] #[derive(Clone, Debug, StateData)]
pub enum AuthSource pub enum AuthSource
{ {
/// Take the token from a cookie with the given name. /// Take the token from a cookie with the given name.
@ -155,6 +161,7 @@ fn main() {
} }
``` ```
*/ */
#[derive(Debug)]
pub struct AuthMiddleware<Data, Handler> pub struct AuthMiddleware<Data, Handler>
{ {
source : AuthSource, source : AuthSource,

View file

@ -1,4 +1,6 @@
#![allow(clippy::tabs_in_doc_comments)] #![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 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 have several RESTful resources that can be added to the gotham router. This crate will take care

View file

@ -86,7 +86,7 @@ route.post("/foo")
# }); # });
``` ```
*/ */
#[derive(Clone)] #[derive(Clone, Debug)]
pub struct AcceptHeaderMatcher pub struct AcceptHeaderMatcher
{ {
types : Vec<Mime>, types : Vec<Mime>,

View file

@ -34,7 +34,7 @@ route.post("/foo")
# }); # });
``` ```
*/ */
#[derive(Clone)] #[derive(Clone, Debug)]
pub struct ContentTypeMatcher pub struct ContentTypeMatcher
{ {
types : Vec<Mime>, types : Vec<Mime>,

View file

@ -21,17 +21,15 @@ impl LookupTableFromTypes for LookupTable
{ {
if include_stars if include_stars
{ {
types return types
.enumerate() .enumerate()
.flat_map(|(i, mime)| vec![("*/*".to_owned(), i), (format!("{}/*", mime.type_()), i), (mime.essence_str().to_owned(), i)].into_iter()) .flat_map(|(i, mime)| vec![("*/*".to_owned(), i), (format!("{}/*", mime.type_()), i), (mime.essence_str().to_owned(), i)].into_iter())
.into_group_map() .into_group_map();
} }
else
{
types types
.enumerate() .enumerate()
.map(|(i, mime)| (mime.essence_str().to_owned(), i)) .map(|(i, mime)| (mime.essence_str().to_owned(), i))
.into_group_map() .into_group_map()
} }
}
} }

View file

@ -16,6 +16,7 @@ pub trait GetOpenapi
fn get_openapi(&mut self, path : &str); fn get_openapi(&mut self, path : &str);
} }
#[derive(Debug)]
pub struct OpenapiRouter<'a, D> pub struct OpenapiRouter<'a, D>
{ {
pub router : &'a mut D, pub router : &'a mut D,

View file

@ -2,6 +2,7 @@ use gotham::hyper::{Body, StatusCode};
use mime::{Mime, APPLICATION_JSON}; use mime::{Mime, APPLICATION_JSON};
/// A response, used to create the final gotham response from. /// A response, used to create the final gotham response from.
#[derive(Debug)]
pub struct Response pub struct Response
{ {
pub status : StatusCode, pub status : StatusCode,

View file

@ -8,7 +8,7 @@ combination with [`AuthSuccess`] or [`AuthResult`].
[`AuthSuccess`]: type.AuthSuccess.html [`AuthSuccess`]: type.AuthSuccess.html
[`AuthResult`]: type.AuthResult.html [`AuthResult`]: type.AuthResult.html
*/ */
#[derive(ResourceError)] #[derive(Debug, Clone, Copy, ResourceError)]
pub enum AuthError pub enum AuthError
{ {
#[status(FORBIDDEN)] #[status(FORBIDDEN)]
@ -54,7 +54,7 @@ error, or delegates to another error type. This type is best used with [`AuthRes
[`AuthResult`]: type.AuthResult.html [`AuthResult`]: type.AuthResult.html
*/ */
#[derive(ResourceError)] #[derive(Debug, ResourceError)]
pub enum AuthErrorOrOther<E> pub enum AuthErrorOrOther<E>
{ {
#[status(UNAUTHORIZED)] #[status(UNAUTHORIZED)]

View file

@ -20,6 +20,7 @@ pub use no_content::NoContent;
mod raw; mod raw;
pub use raw::Raw; pub use raw::Raw;
//#[allow(clippy::module_inception)]
mod result; mod result;
pub use result::IntoResponseError; pub use result::IntoResponseError;

View file

@ -31,7 +31,7 @@ fn read_all(_state: &mut State) {
# } # }
``` ```
*/ */
#[derive(Clone, Copy, Default)] #[derive(Clone, Copy, Debug, Default)]
pub struct NoContent; pub struct NoContent;
impl From<()> for NoContent impl From<()> for NoContent

View file

@ -53,7 +53,7 @@ pub trait WithOpenapi<D>
{ {
fn with_openapi<F>(&mut self, info : OpenapiInfo, block : F) fn with_openapi<F>(&mut self, info : OpenapiInfo, block : F)
where where
F : FnOnce(OpenapiRouter<D>); F : FnOnce(OpenapiRouter<'_, D>);
} }
/// This trait adds the `resource` method to gotham's routing. It allows you to register /// 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<F>(&mut self, info : OpenapiInfo, block : F) fn with_openapi<F>(&mut self, info : OpenapiInfo, block : F)
where where
F : FnOnce(OpenapiRouter<$implType<'a, C, P>>) F : FnOnce(OpenapiRouter<'_, $implType<'a, C, P>>)
{ {
let router = OpenapiRouter { let router = OpenapiRouter {
router: self, router: self,