1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-02-22 20:52:27 +00:00

apply some clippy suggestions

This commit is contained in:
Dominic 2021-01-01 18:03:31 +01:00
parent 6ee382242b
commit 388bf8b49c
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
8 changed files with 23 additions and 8 deletions

View file

@ -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};

View file

@ -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)]
/*!

View file

@ -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<B: Into<Body>>(status: StatusCode, body: B, mime: Option<Mime>) -> 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<B: Into<Body>>(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,

View file

@ -125,7 +125,7 @@ where
type Err = Res::Err;
fn into_response(self) -> Pin<Box<dyn Future<Output = Result<Response, Self::Err>> + Send>> {
self.then(|result| result.into_response()).boxed()
self.then(ResourceResult::into_response).boxed()
}
fn accepted_types() -> Option<Vec<Mime>> {

View file

@ -92,7 +92,7 @@ where
type Err = SerdeJsonError; // just for easier handling of `Result<Raw<T>, E>`
fn into_response(self) -> Pin<Box<dyn Future<Output = Result<Response, SerdeJsonError>> + 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")]

View file

@ -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]

View file

@ -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]

View file

@ -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}
},