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

start moving shit over to async

This commit is contained in:
Dominic 2020-04-14 21:17:12 +02:00
parent f425f21ff3
commit ede0d75161
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
2 changed files with 239 additions and 93 deletions

View file

@ -1,6 +1,8 @@
use crate::{ResponseBody, StatusCode}; use crate::{ResponseBody, StatusCode};
#[cfg(feature = "openapi")] #[cfg(feature = "openapi")]
use crate::{OpenapiSchema, OpenapiType}; use crate::{OpenapiSchema, OpenapiType};
use futures_core::future::Future;
use futures_util::{future, future::FutureExt};
use gotham::hyper::Body; use gotham::hyper::Body;
#[cfg(feature = "errorlog")] #[cfg(feature = "errorlog")]
use log::error; use log::error;
@ -11,7 +13,8 @@ use serde::Serialize;
use serde_json::error::Error as SerdeJsonError; use serde_json::error::Error as SerdeJsonError;
use std::{ use std::{
error::Error, error::Error,
fmt::Debug fmt::Debug,
pin::Pin
}; };
/// A response, used to create the final gotham response from. /// A response, used to create the final gotham response from.
@ -75,12 +78,15 @@ impl Response
} }
} }
/// A trait provided to convert a resource's result to json. /// A trait provided to convert a resource's result to json.
pub trait ResourceResult pub trait ResourceResult
{ {
type Err : Error + Send + 'static;
/// Turn this into a response that can be returned to the browser. This api will likely /// Turn this into a response that can be returned to the browser. This api will likely
/// change in the future. /// change in the future.
fn into_response(self) -> Result<Response, SerdeJsonError>; fn into_response(self) -> Pin<Box<dyn Future<Output = Result<Response, Self::Err>> + Send>>;
/// Return a list of supported mime types. /// Return a list of supported mime types.
fn accepted_types() -> Option<Vec<Mime>> fn accepted_types() -> Option<Vec<Mime>>
@ -126,6 +132,15 @@ impl<T : ToString> From<T> for ResourceError
} }
} }
fn into_response_helper<Err, F>(create_response : F) -> Pin<Box<dyn Future<Output = Result<Response, Err>> + Send>>
where
Err : Send + 'static,
F : FnOnce() -> Result<Response, Err>
{
let res = create_response();
async move { res }.boxed()
}
#[cfg(feature = "errorlog")] #[cfg(feature = "errorlog")]
fn errorlog<E : std::fmt::Display>(e : E) fn errorlog<E : std::fmt::Display>(e : E)
{ {
@ -137,8 +152,11 @@ fn errorlog<E>(_e : E) {}
impl<R : ResponseBody, E : Error> ResourceResult for Result<R, E> impl<R : ResponseBody, E : Error> ResourceResult for Result<R, E>
{ {
fn into_response(self) -> Result<Response, SerdeJsonError> type Err = SerdeJsonError;
fn into_response(self) -> Pin<Box<dyn Future<Output = Result<Response, SerdeJsonError>> + Send>>
{ {
into_response_helper(|| {
Ok(match self { Ok(match self {
Ok(r) => Response::json(StatusCode::OK, serde_json::to_string(&r)?), Ok(r) => Response::json(StatusCode::OK, serde_json::to_string(&r)?),
Err(e) => { Err(e) => {
@ -147,6 +165,7 @@ impl<R : ResponseBody, E : Error> ResourceResult for Result<R, E>
Response::json(StatusCode::INTERNAL_SERVER_ERROR, serde_json::to_string(&err)?) Response::json(StatusCode::INTERNAL_SERVER_ERROR, serde_json::to_string(&err)?)
} }
}) })
})
} }
fn accepted_types() -> Option<Vec<Mime>> fn accepted_types() -> Option<Vec<Mime>>
@ -161,6 +180,40 @@ impl<R : ResponseBody, E : Error> ResourceResult for Result<R, E>
} }
} }
impl<Res> ResourceResult for Pin<Box<dyn Future<Output = Res> + Send>>
where
Res : ResourceResult + 'static,
dyn Future<Output = Result<Response, Res::Err>> : Send
{
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()
}
fn accepted_types() -> Option<Vec<Mime>>
{
Res::accepted_types()
}
#[cfg(feature = "openapi")]
fn schema() -> OpenapiSchema
{
Res::schema()
}
#[cfg(feature = "openapi")]
fn default_status() -> StatusCode
{
Res::default_status()
}
}
/** /**
This can be returned from a resource when there is no cause of an error. For example: This can be returned from a resource when there is no cause of an error. For example:
@ -215,9 +268,11 @@ impl<T : Debug> Debug for Success<T>
impl<T : ResponseBody> ResourceResult for Success<T> impl<T : ResponseBody> ResourceResult for Success<T>
{ {
fn into_response(self) -> Result<Response, SerdeJsonError> type Err = SerdeJsonError;
fn into_response(self) -> Pin<Box<dyn Future<Output = Result<Response, SerdeJsonError>> + Send>>
{ {
Ok(Response::json(StatusCode::OK, serde_json::to_string(&self.0)?)) into_response_helper(|| Ok(Response::json(StatusCode::OK, serde_json::to_string(&self.0)?)))
} }
fn accepted_types() -> Option<Vec<Mime>> fn accepted_types() -> Option<Vec<Mime>>
@ -318,12 +373,14 @@ impl<T : Debug> Debug for AuthResult<T>
impl<T : ResourceResult> ResourceResult for AuthResult<T> impl<T : ResourceResult> ResourceResult for AuthResult<T>
{ {
fn into_response(self) -> Result<Response, SerdeJsonError> type Err = T::Err;
fn into_response(self) -> Pin<Box<dyn Future<Output = Result<Response, Self::Err>> + Send>>
{ {
match self match self
{ {
Self::Ok(res) => res.into_response(), Self::Ok(res) => res.into_response(),
Self::AuthErr => Ok(Response::forbidden()) Self::AuthErr => future::ok(Response::forbidden()).boxed()
} }
} }
@ -379,10 +436,12 @@ impl From<()> for NoContent
impl ResourceResult for NoContent impl ResourceResult for NoContent
{ {
type Err = SerdeJsonError; // just for easier handling of `Result<NoContent, E>`
/// This will always be a _204 No Content_ together with an empty string. /// This will always be a _204 No Content_ together with an empty string.
fn into_response(self) -> Result<Response, SerdeJsonError> fn into_response(self) -> Pin<Box<dyn Future<Output = Result<Response, Self::Err>> + Send>>
{ {
Ok(Response::no_content()) future::ok(Response::no_content()).boxed()
} }
/// Returns the schema of the `()` type. /// Returns the schema of the `()` type.
@ -402,14 +461,16 @@ impl ResourceResult for NoContent
impl<E : Error> ResourceResult for Result<NoContent, E> impl<E : Error> ResourceResult for Result<NoContent, E>
{ {
fn into_response(self) -> Result<Response, SerdeJsonError> type Err = SerdeJsonError;
fn into_response(self) -> Pin<Box<dyn Future<Output = Result<Response, SerdeJsonError>> + Send>>
{ {
match self { match self {
Ok(nc) => nc.into_response(), Ok(nc) => nc.into_response(),
Err(e) => { Err(e) => into_response_helper(|| {
let err : ResourceError = e.into(); let err : ResourceError = e.into();
Ok(Response::json(StatusCode::INTERNAL_SERVER_ERROR, serde_json::to_string(&err)?)) Ok(Response::json(StatusCode::INTERNAL_SERVER_ERROR, serde_json::to_string(&err)?))
} })
} }
} }
@ -460,9 +521,11 @@ impl<T : Debug> Debug for Raw<T>
impl<T : Into<Body>> ResourceResult for Raw<T> impl<T : Into<Body>> ResourceResult for Raw<T>
{ {
fn into_response(self) -> Result<Response, SerdeJsonError> 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>>
{ {
Ok(Response::new(StatusCode::OK, self.raw, Some(self.mime.clone()))) future::ok(Response::new(StatusCode::OK, self.raw, Some(self.mime.clone()))).boxed()
} }
fn accepted_types() -> Option<Vec<Mime>> fn accepted_types() -> Option<Vec<Mime>>
@ -482,16 +545,18 @@ impl<T : Into<Body>> ResourceResult for Raw<T>
impl<T, E : Error> ResourceResult for Result<Raw<T>, E> impl<T, E : Error> ResourceResult for Result<Raw<T>, E>
where where
Raw<T> : ResourceResult Raw<T> : ResourceResult<Err = SerdeJsonError>
{ {
fn into_response(self) -> Result<Response, SerdeJsonError> type Err = SerdeJsonError;
fn into_response(self) -> Pin<Box<dyn Future<Output = Result<Response, SerdeJsonError>> + Send>>
{ {
match self { match self {
Ok(raw) => raw.into_response(), Ok(raw) => raw.into_response(),
Err(e) => { Err(e) => into_response_helper(|| {
let err : ResourceError = e.into(); let err : ResourceError = e.into();
Ok(Response::json(StatusCode::INTERNAL_SERVER_ERROR, serde_json::to_string(&err)?)) Ok(Response::json(StatusCode::INTERNAL_SERVER_ERROR, serde_json::to_string(&err)?))
} })
} }
} }
@ -512,6 +577,7 @@ where
mod test mod test
{ {
use super::*; use super::*;
use futures_executor::block_on;
use mime::TEXT_PLAIN; use mime::TEXT_PLAIN;
use thiserror::Error; use thiserror::Error;
@ -530,7 +596,7 @@ mod test
fn resource_result_ok() fn resource_result_ok()
{ {
let ok : Result<Msg, MsgError> = Ok(Msg::default()); let ok : Result<Msg, MsgError> = Ok(Msg::default());
let res = ok.into_response().expect("didn't expect error response"); let res = block_on(ok.into_response()).expect("didn't expect error response");
assert_eq!(res.status, StatusCode::OK); assert_eq!(res.status, StatusCode::OK);
assert_eq!(res.mime, Some(APPLICATION_JSON)); assert_eq!(res.mime, Some(APPLICATION_JSON));
assert_eq!(res.full_body().unwrap(), r#"{"msg":""}"#.as_bytes()); assert_eq!(res.full_body().unwrap(), r#"{"msg":""}"#.as_bytes());
@ -540,7 +606,7 @@ mod test
fn resource_result_err() fn resource_result_err()
{ {
let err : Result<Msg, MsgError> = Err(MsgError::default()); let err : Result<Msg, MsgError> = Err(MsgError::default());
let res = err.into_response().expect("didn't expect error response"); let res = block_on(err.into_response()).expect("didn't expect error response");
assert_eq!(res.status, StatusCode::INTERNAL_SERVER_ERROR); assert_eq!(res.status, StatusCode::INTERNAL_SERVER_ERROR);
assert_eq!(res.mime, Some(APPLICATION_JSON)); assert_eq!(res.mime, Some(APPLICATION_JSON));
assert_eq!(res.full_body().unwrap(), format!(r#"{{"error":true,"message":"{}"}}"#, MsgError::default()).as_bytes()); assert_eq!(res.full_body().unwrap(), format!(r#"{{"error":true,"message":"{}"}}"#, MsgError::default()).as_bytes());
@ -550,7 +616,7 @@ mod test
fn success_always_successfull() fn success_always_successfull()
{ {
let success : Success<Msg> = Msg::default().into(); let success : Success<Msg> = Msg::default().into();
let res = success.into_response().expect("didn't expect error response"); let res = block_on(success.into_response()).expect("didn't expect error response");
assert_eq!(res.status, StatusCode::OK); assert_eq!(res.status, StatusCode::OK);
assert_eq!(res.mime, Some(APPLICATION_JSON)); assert_eq!(res.mime, Some(APPLICATION_JSON));
assert_eq!(res.full_body().unwrap(), r#"{"msg":""}"#.as_bytes()); assert_eq!(res.full_body().unwrap(), r#"{"msg":""}"#.as_bytes());
@ -560,7 +626,7 @@ mod test
fn no_content_has_empty_response() fn no_content_has_empty_response()
{ {
let no_content = NoContent::default(); let no_content = NoContent::default();
let res = no_content.into_response().expect("didn't expect error response"); let res = block_on(no_content.into_response()).expect("didn't expect error response");
assert_eq!(res.status, StatusCode::NO_CONTENT); assert_eq!(res.status, StatusCode::NO_CONTENT);
assert_eq!(res.mime, None); assert_eq!(res.mime, None);
assert_eq!(res.full_body().unwrap(), &[] as &[u8]); assert_eq!(res.full_body().unwrap(), &[] as &[u8]);
@ -570,7 +636,7 @@ mod test
fn no_content_result() fn no_content_result()
{ {
let no_content : Result<NoContent, MsgError> = Ok(NoContent::default()); let no_content : Result<NoContent, MsgError> = Ok(NoContent::default());
let res = no_content.into_response().expect("didn't expect error response"); let res = block_on(no_content.into_response()).expect("didn't expect error response");
assert_eq!(res.status, StatusCode::NO_CONTENT); assert_eq!(res.status, StatusCode::NO_CONTENT);
assert_eq!(res.mime, None); assert_eq!(res.mime, None);
assert_eq!(res.full_body().unwrap(), &[] as &[u8]); assert_eq!(res.full_body().unwrap(), &[] as &[u8]);
@ -581,7 +647,7 @@ mod test
{ {
let msg = "Test"; let msg = "Test";
let raw = Raw::new(msg, TEXT_PLAIN); let raw = Raw::new(msg, TEXT_PLAIN);
let res = raw.into_response().expect("didn't expect error response"); let res = block_on(raw.into_response()).expect("didn't expect error response");
assert_eq!(res.status, StatusCode::OK); assert_eq!(res.status, StatusCode::OK);
assert_eq!(res.mime, Some(TEXT_PLAIN)); assert_eq!(res.mime, Some(TEXT_PLAIN));
assert_eq!(res.full_body().unwrap(), msg.as_bytes()); assert_eq!(res.full_body().unwrap(), msg.as_bytes());

View file

@ -7,9 +7,10 @@ use crate::{
#[cfg(feature = "openapi")] #[cfg(feature = "openapi")]
use crate::OpenapiRouter; use crate::OpenapiRouter;
use futures_core::future::Future;
use futures_util::{future, future::FutureExt}; use futures_util::{future, future::FutureExt};
use gotham::{ use gotham::{
handler::{HandlerFuture, IntoHandlerError, IntoHandlerFuture}, handler::{HandlerError, HandlerFuture, IntoHandlerError, IntoHandlerFuture},
helpers::http::response::{create_empty_response, create_response}, helpers::http::response::{create_empty_response, create_response},
pipeline::chain::PipelineHandleChain, pipeline::chain::PipelineHandleChain,
router::{ router::{
@ -65,14 +66,40 @@ pub trait DrawResources
/// `Resource::setup` method. /// `Resource::setup` method.
pub trait DrawResourceRoutes pub trait DrawResourceRoutes
{ {
fn read_all<Handler : ResourceReadAll>(&mut self); fn read_all<Handler : ResourceReadAll>(&mut self)
fn read<Handler : ResourceRead>(&mut self); where
fn search<Handler : ResourceSearch>(&mut self); dyn Future<Output = Result<Response, <Handler::Res as ResourceResult>::Err>> : Send;
fn create<Handler : ResourceCreate>(&mut self);
fn update_all<Handler : ResourceUpdateAll>(&mut self); fn read<Handler : ResourceRead>(&mut self)
fn update<Handler : ResourceUpdate>(&mut self); where
fn delete_all<Handler : ResourceDeleteAll>(&mut self); dyn Future<Output = Result<Response, <Handler::Res as ResourceResult>::Err>> : Send;
fn delete<Handler : ResourceDelete>(&mut self);
fn search<Handler : ResourceSearch>(&mut self)
where
dyn Future<Output = Result<Response, <Handler::Res as ResourceResult>::Err>> : Send;
fn create<Handler : ResourceCreate>(&mut self)
where
Handler::Res : Send + 'static,
Handler::Body : 'static;
fn update_all<Handler : ResourceUpdateAll>(&mut self)
where
Handler::Res : Send + 'static,
Handler::Body : 'static;
fn update<Handler : ResourceUpdate>(&mut self)
where
Handler::Res : Send + 'static,
Handler::Body : 'static;
fn delete_all<Handler : ResourceDeleteAll>(&mut self)
where
dyn Future<Output = Result<Response, <Handler::Res as ResourceResult>::Err>> : Send;
fn delete<Handler : ResourceDelete>(&mut self)
where
dyn Future<Output = Result<Response, <Handler::Res as ResourceResult>::Err>> : Send;
} }
fn response_from(res : Response, state : &State) -> hyper::Response<Body> fn response_from(res : Response, state : &State) -> hyper::Response<Body>
@ -92,9 +119,11 @@ fn response_from(res : Response, state : &State) -> hyper::Response<Body>
fn to_handler_future<F, R>(mut state : State, get_result : F) -> Pin<Box<HandlerFuture>> fn to_handler_future<F, R>(mut state : State, get_result : F) -> Pin<Box<HandlerFuture>>
where where
F : FnOnce(&mut State) -> R, F : FnOnce(&mut State) -> R,
R : ResourceResult R : ResourceResult,
dyn Future<Output = Result<Response, R::Err>> : Send
{ {
let res = get_result(&mut state).into_response(); get_result(&mut state).into_response()
.then(|res|
match res { match res {
Ok(res) => { Ok(res) => {
let r = response_from(res, &state); let r = response_from(res, &state);
@ -102,64 +131,81 @@ where
}, },
Err(e) => future::err((state, e.into_handler_error())).boxed() Err(e) => future::err((state, e.into_handler_error())).boxed()
} }
).boxed()
} }
fn handle_with_body<Body, F, R>(mut state : State, get_result : F) -> Pin<Box<HandlerFuture>> async fn body_to_res<B, F, R>(state : &mut State, get_result : F) -> Result<gotham::hyper::Response<Body>, HandlerError>
where where
Body : RequestBody, B : RequestBody,
F : FnOnce(&mut State, Body) -> R + Send + 'static, F : FnOnce(&mut State, B) -> R,
R : ResourceResult R : ResourceResult
{ {
let f = to_bytes(gotham::hyper::Body::take_from(&mut state)) let body = to_bytes(Body::take_from(&mut state)).await;
.then(|body| {
let body = match body { let body = match body {
Ok(body) => body, Ok(body) => body,
Err(e) => return future::err((state, e.into_handler_error())) Err(e) => return Err(e.into_handler_error())
}; };
let content_type : Mime = match HeaderMap::borrow_from(&state).get(CONTENT_TYPE) { let content_type : Mime = match HeaderMap::borrow_from(&state).get(CONTENT_TYPE) {
Some(content_type) => content_type.to_str().unwrap().parse().unwrap(), Some(content_type) => content_type.to_str().unwrap().parse().unwrap(),
None => { None => {
let res = create_empty_response(&state, StatusCode::UNSUPPORTED_MEDIA_TYPE); let res = create_empty_response(&state, StatusCode::UNSUPPORTED_MEDIA_TYPE);
return future::ok((state, res)) return Ok(res)
} }
}; };
let body = match Body::from_body(body, content_type) { let res = {
let body = match B::from_body(body, content_type) {
Ok(body) => body, Ok(body) => body,
Err(e) => return { Err(e) => return {
let error : ResourceError = e.into(); let error : ResourceError = e.into();
match serde_json::to_string(&error) { match serde_json::to_string(&error) {
Ok(json) => { Ok(json) => {
let res = create_response(&state, StatusCode::BAD_REQUEST, APPLICATION_JSON, json); let res = create_response(&state, StatusCode::BAD_REQUEST, APPLICATION_JSON, json);
future::ok((state, res)) Ok(res)
}, },
Err(e) => future::err((state, e.into_handler_error())) Err(e) => Err(e.into_handler_error())
} }
} }
}; };
get_result(&mut state, body)
};
let res = get_result(&mut state, body).into_response(); let res = res.into_response().await;
match res { match res {
Ok(res) => { Ok(res) => {
let r = response_from(res, &state); let r = response_from(res, &state);
future::ok((state, r)) Ok(r)
}, },
Err(e) => future::err((state, e.into_handler_error())) Err(e) => Err(e.into_handler_error())
}
} }
}); fn handle_with_body<B, F, R>(mut state : State, get_result : F) -> Pin<Box<HandlerFuture>>
where
f.boxed() B : RequestBody + 'static,
F : FnOnce(&mut State, B) -> R + Send + 'static,
R : ResourceResult + Send + 'static
{
body_to_res(&mut state, get_result)
.then(|res| match res {
Ok(ok) => future::ok((state, ok)),
Err(err) => future::err((state, err))
})
.boxed()
} }
fn read_all_handler<Handler : ResourceReadAll>(state : State) -> Pin<Box<HandlerFuture>> fn read_all_handler<Handler : ResourceReadAll>(state : State) -> Pin<Box<HandlerFuture>>
where
dyn Future<Output = Result<Response, <Handler::Res as ResourceResult>::Err>> : Send
{ {
to_handler_future(state, |state| Handler::read_all(state)) to_handler_future(state, |state| Handler::read_all(state))
} }
fn read_handler<Handler : ResourceRead>(state : State) -> Pin<Box<HandlerFuture>> fn read_handler<Handler : ResourceRead>(state : State) -> Pin<Box<HandlerFuture>>
where
dyn Future<Output = Result<Response, <Handler::Res as ResourceResult>::Err>> : Send
{ {
let id = { let id = {
let path : &PathExtractor<Handler::ID> = PathExtractor::borrow_from(&state); let path : &PathExtractor<Handler::ID> = PathExtractor::borrow_from(&state);
@ -169,22 +215,33 @@ fn read_handler<Handler : ResourceRead>(state : State) -> Pin<Box<HandlerFuture>
} }
fn search_handler<Handler : ResourceSearch>(mut state : State) -> Pin<Box<HandlerFuture>> fn search_handler<Handler : ResourceSearch>(mut state : State) -> Pin<Box<HandlerFuture>>
where
dyn Future<Output = Result<Response, <Handler::Res as ResourceResult>::Err>> : Send
{ {
let query = Handler::Query::take_from(&mut state); let query = Handler::Query::take_from(&mut state);
to_handler_future(state, |state| Handler::search(state, query)) to_handler_future(state, |state| Handler::search(state, query))
} }
fn create_handler<Handler : ResourceCreate>(state : State) -> Pin<Box<HandlerFuture>> fn create_handler<Handler : ResourceCreate>(state : State) -> Pin<Box<HandlerFuture>>
where
Handler::Res : Send + 'static,
Handler::Body : 'static
{ {
handle_with_body::<Handler::Body, _, _>(state, |state, body| Handler::create(state, body)) handle_with_body::<Handler::Body, _, _>(state, |state, body| Handler::create(state, body))
} }
fn update_all_handler<Handler : ResourceUpdateAll>(state : State) -> Pin<Box<HandlerFuture>> fn update_all_handler<Handler : ResourceUpdateAll>(state : State) -> Pin<Box<HandlerFuture>>
where
Handler::Res : Send + 'static,
Handler::Body : 'static
{ {
handle_with_body::<Handler::Body, _, _>(state, |state, body| Handler::update_all(state, body)) handle_with_body::<Handler::Body, _, _>(state, |state, body| Handler::update_all(state, body))
} }
fn update_handler<Handler : ResourceUpdate>(state : State) -> Pin<Box<HandlerFuture>> fn update_handler<Handler : ResourceUpdate>(state : State) -> Pin<Box<HandlerFuture>>
where
Handler::Res : Send + 'static,
Handler::Body : 'static
{ {
let id = { let id = {
let path : &PathExtractor<Handler::ID> = PathExtractor::borrow_from(&state); let path : &PathExtractor<Handler::ID> = PathExtractor::borrow_from(&state);
@ -194,11 +251,15 @@ fn update_handler<Handler : ResourceUpdate>(state : State) -> Pin<Box<HandlerFut
} }
fn delete_all_handler<Handler : ResourceDeleteAll>(state : State) -> Pin<Box<HandlerFuture>> fn delete_all_handler<Handler : ResourceDeleteAll>(state : State) -> Pin<Box<HandlerFuture>>
where
dyn Future<Output = Result<Response, <Handler::Res as ResourceResult>::Err>> : Send
{ {
to_handler_future(state, |state| Handler::delete_all(state)) to_handler_future(state, |state| Handler::delete_all(state))
} }
fn delete_handler<Handler : ResourceDelete>(state : State) -> Pin<Box<HandlerFuture>> fn delete_handler<Handler : ResourceDelete>(state : State) -> Pin<Box<HandlerFuture>>
where
dyn Future<Output = Result<Response, <Handler::Res as ResourceResult>::Err>> : Send
{ {
let id = { let id = {
let path : &PathExtractor<Handler::ID> = PathExtractor::borrow_from(&state); let path : &PathExtractor<Handler::ID> = PathExtractor::borrow_from(&state);
@ -297,6 +358,8 @@ macro_rules! implDrawResourceRoutes {
P : RefUnwindSafe + Send + Sync + 'static P : RefUnwindSafe + Send + Sync + 'static
{ {
fn read_all<Handler : ResourceReadAll>(&mut self) fn read_all<Handler : ResourceReadAll>(&mut self)
where
dyn Future<Output = Result<Response, <Handler::Res as ResourceResult>::Err>> : Send
{ {
let matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into(); let matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into();
self.0.get(&self.1) self.0.get(&self.1)
@ -305,6 +368,8 @@ macro_rules! implDrawResourceRoutes {
} }
fn read<Handler : ResourceRead>(&mut self) fn read<Handler : ResourceRead>(&mut self)
where
dyn Future<Output = Result<Response, <Handler::Res as ResourceResult>::Err>> : Send
{ {
let matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into(); let matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into();
self.0.get(&format!("{}/:id", self.1)) self.0.get(&format!("{}/:id", self.1))
@ -314,6 +379,8 @@ macro_rules! implDrawResourceRoutes {
} }
fn search<Handler : ResourceSearch>(&mut self) fn search<Handler : ResourceSearch>(&mut self)
where
dyn Future<Output = Result<Response, <Handler::Res as ResourceResult>::Err>> : Send
{ {
let matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into(); let matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into();
self.0.get(&format!("{}/search", self.1)) self.0.get(&format!("{}/search", self.1))
@ -323,6 +390,9 @@ macro_rules! implDrawResourceRoutes {
} }
fn create<Handler : ResourceCreate>(&mut self) fn create<Handler : ResourceCreate>(&mut self)
where
Handler::Res : Send + 'static,
Handler::Body : 'static
{ {
let accept_matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into(); let accept_matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into();
let content_matcher : MaybeMatchContentTypeHeader = Handler::Body::supported_types().into(); let content_matcher : MaybeMatchContentTypeHeader = Handler::Body::supported_types().into();
@ -333,6 +403,9 @@ macro_rules! implDrawResourceRoutes {
} }
fn update_all<Handler : ResourceUpdateAll>(&mut self) fn update_all<Handler : ResourceUpdateAll>(&mut self)
where
Handler::Res : Send + 'static,
Handler::Body : 'static
{ {
let accept_matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into(); let accept_matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into();
let content_matcher : MaybeMatchContentTypeHeader = Handler::Body::supported_types().into(); let content_matcher : MaybeMatchContentTypeHeader = Handler::Body::supported_types().into();
@ -343,6 +416,9 @@ macro_rules! implDrawResourceRoutes {
} }
fn update<Handler : ResourceUpdate>(&mut self) fn update<Handler : ResourceUpdate>(&mut self)
where
Handler::Res : Send + 'static,
Handler::Body : 'static
{ {
let accept_matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into(); let accept_matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into();
let content_matcher : MaybeMatchContentTypeHeader = Handler::Body::supported_types().into(); let content_matcher : MaybeMatchContentTypeHeader = Handler::Body::supported_types().into();
@ -354,6 +430,8 @@ macro_rules! implDrawResourceRoutes {
} }
fn delete_all<Handler : ResourceDeleteAll>(&mut self) fn delete_all<Handler : ResourceDeleteAll>(&mut self)
where
dyn Future<Output = Result<Response, <Handler::Res as ResourceResult>::Err>> : Send
{ {
let matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into(); let matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into();
self.0.delete(&self.1) self.0.delete(&self.1)
@ -362,6 +440,8 @@ macro_rules! implDrawResourceRoutes {
} }
fn delete<Handler : ResourceDelete>(&mut self) fn delete<Handler : ResourceDelete>(&mut self)
where
dyn Future<Output = Result<Response, <Handler::Res as ResourceResult>::Err>> : Send
{ {
let matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into(); let matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into();
self.0.delete(&format!("{}/:id", self.1)) self.0.delete(&format!("{}/:id", self.1))