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:
parent
6ee382242b
commit
388bf8b49c
8 changed files with 23 additions and 8 deletions
|
@ -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};
|
||||
|
|
|
@ -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)]
|
||||
/*!
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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>> {
|
||||
|
|
|
@ -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")]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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}
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue