1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-04-19 22:44:38 +00:00

require all resource results to be sendable

This commit is contained in:
Dominic 2020-04-14 22:44:43 +02:00
parent 06e6c93a46
commit d7282786b1
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
3 changed files with 20 additions and 11 deletions

View file

@ -419,7 +419,7 @@ macro_rules! implOpenapiRouter {
fn create<Handler : ResourceCreate>(&mut self) fn create<Handler : ResourceCreate>(&mut self)
where where
Handler::Res : Send + 'static, Handler::Res : 'static,
Handler::Body : 'static Handler::Body : 'static
{ {
let schema = (self.0).1.add_schema::<Handler::Res>(); let schema = (self.0).1.add_schema::<Handler::Res>();
@ -435,7 +435,7 @@ macro_rules! implOpenapiRouter {
fn update_all<Handler : ResourceUpdateAll>(&mut self) fn update_all<Handler : ResourceUpdateAll>(&mut self)
where where
Handler::Res : Send + 'static, Handler::Res : 'static,
Handler::Body : 'static Handler::Body : 'static
{ {
let schema = (self.0).1.add_schema::<Handler::Res>(); let schema = (self.0).1.add_schema::<Handler::Res>();
@ -451,7 +451,7 @@ macro_rules! implOpenapiRouter {
fn update<Handler : ResourceUpdate>(&mut self) fn update<Handler : ResourceUpdate>(&mut self)
where where
Handler::Res : Send + 'static, Handler::Res : 'static,
Handler::Body : 'static Handler::Body : 'static
{ {
let schema = (self.0).1.add_schema::<Handler::Res>(); let schema = (self.0).1.add_schema::<Handler::Res>();

View file

@ -80,7 +80,7 @@ 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 : Send
{ {
type Err : Error + Send + 'static; type Err : Error + Send + 'static;
@ -151,6 +151,8 @@ fn errorlog<E : std::fmt::Display>(e : E)
fn errorlog<E>(_e : E) {} 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>
where
Self : Send
{ {
type Err = SerdeJsonError; type Err = SerdeJsonError;
@ -267,6 +269,8 @@ impl<T : Debug> Debug for Success<T>
} }
impl<T : ResponseBody> ResourceResult for Success<T> impl<T : ResponseBody> ResourceResult for Success<T>
where
Self : Send
{ {
type Err = SerdeJsonError; type Err = SerdeJsonError;
@ -460,6 +464,8 @@ impl ResourceResult for NoContent
} }
impl<E : Error> ResourceResult for Result<NoContent, E> impl<E : Error> ResourceResult for Result<NoContent, E>
where
Self : Send
{ {
type Err = SerdeJsonError; type Err = SerdeJsonError;
@ -520,6 +526,8 @@ impl<T : Debug> Debug for Raw<T>
} }
impl<T : Into<Body>> ResourceResult for Raw<T> impl<T : Into<Body>> ResourceResult for Raw<T>
where
Self : Send
{ {
type Err = SerdeJsonError; // just for easier handling of `Result<Raw<T>, E>` type Err = SerdeJsonError; // just for easier handling of `Result<Raw<T>, E>`
@ -545,6 +553,7 @@ 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
Self : Send,
Raw<T> : ResourceResult<Err = SerdeJsonError> Raw<T> : ResourceResult<Err = SerdeJsonError>
{ {
type Err = SerdeJsonError; type Err = SerdeJsonError;

View file

@ -73,17 +73,17 @@ pub trait DrawResourceRoutes
fn create<Handler : ResourceCreate>(&mut self) fn create<Handler : ResourceCreate>(&mut self)
where where
Handler::Res : Send + 'static, Handler::Res : 'static,
Handler::Body : 'static; Handler::Body : 'static;
fn update_all<Handler : ResourceUpdateAll>(&mut self) fn update_all<Handler : ResourceUpdateAll>(&mut self)
where where
Handler::Res : Send + 'static, Handler::Res : 'static,
Handler::Body : 'static; Handler::Body : 'static;
fn update<Handler : ResourceUpdate>(&mut self) fn update<Handler : ResourceUpdate>(&mut self)
where where
Handler::Res : Send + 'static, Handler::Res : 'static,
Handler::Body : 'static; Handler::Body : 'static;
fn delete_all<Handler : ResourceDeleteAll>(&mut self); fn delete_all<Handler : ResourceDeleteAll>(&mut self);
@ -175,7 +175,7 @@ fn handle_with_body<B, F, R>(state : State, get_result : F) -> Pin<Box<HandlerFu
where where
B : RequestBody + 'static, B : RequestBody + 'static,
F : FnOnce(&mut State, B) -> R + Send + 'static, F : FnOnce(&mut State, B) -> R + Send + 'static,
R : ResourceResult + Send + 'static R : ResourceResult + 'static
{ {
body_to_res(state, get_result) body_to_res(state, get_result)
.then(|(state, res)| match res { .then(|(state, res)| match res {
@ -207,7 +207,7 @@ fn search_handler<Handler : ResourceSearch>(mut state : State) -> Pin<Box<Handle
fn create_handler<Handler : ResourceCreate>(state : State) -> Pin<Box<HandlerFuture>> fn create_handler<Handler : ResourceCreate>(state : State) -> Pin<Box<HandlerFuture>>
where where
Handler::Res : Send + 'static, Handler::Res : 'static,
Handler::Body : '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))
@ -215,7 +215,7 @@ where
fn update_all_handler<Handler : ResourceUpdateAll>(state : State) -> Pin<Box<HandlerFuture>> fn update_all_handler<Handler : ResourceUpdateAll>(state : State) -> Pin<Box<HandlerFuture>>
where where
Handler::Res : Send + 'static, Handler::Res : 'static,
Handler::Body : '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))
@ -223,7 +223,7 @@ where
fn update_handler<Handler : ResourceUpdate>(state : State) -> Pin<Box<HandlerFuture>> fn update_handler<Handler : ResourceUpdate>(state : State) -> Pin<Box<HandlerFuture>>
where where
Handler::Res : Send + 'static, Handler::Res : 'static,
Handler::Body : 'static Handler::Body : 'static
{ {
let id = { let id = {