mirror of https://github.com/rwf2/Rocket.git
Allow catchers to be async fn.
This commit is contained in:
parent
0ab787e216
commit
1c28a9413b
|
@ -54,7 +54,7 @@ pub fn _catch(args: TokenStream, input: TokenStream) -> Result<TokenStream> {
|
|||
define_vars_and_mods!(req, catcher, Request, Response, ErrorHandlerFuture);
|
||||
|
||||
// Determine the number of parameters that will be passed in.
|
||||
let (fn_sig, inputs) = match catch.function.sig.inputs.len() {
|
||||
let (_fn_sig, inputs) = match catch.function.sig.inputs.len() {
|
||||
0 => (quote!(fn() -> _), quote!()),
|
||||
1 => (quote!(fn(&#Request) -> _), quote!(#req)),
|
||||
_ => return Err(catch.function.sig.inputs.span()
|
||||
|
@ -71,10 +71,22 @@ pub fn _catch(args: TokenStream, input: TokenStream) -> Result<TokenStream> {
|
|||
.map(|ty| ty.span().into())
|
||||
.unwrap_or(Span::call_site().into());
|
||||
|
||||
let responder_stmt = if catch.function.sig.asyncness.is_some() {
|
||||
quote_spanned! { return_type_span =>
|
||||
let ___responder = #catcher(#inputs).await;
|
||||
}
|
||||
} else {
|
||||
quote_spanned! { return_type_span =>
|
||||
let ___responder = #catcher(#inputs);
|
||||
}
|
||||
};
|
||||
|
||||
let catcher_response = quote_spanned!(return_type_span => {
|
||||
// Emit this to force a type signature check.
|
||||
let #catcher: #fn_sig = #user_catcher_fn_name;
|
||||
let ___responder = #catcher(#inputs);
|
||||
// TODO.async: fix this
|
||||
// // Emit this to force a type signature check.
|
||||
// let #catcher: #fn_sig = #user_catcher_fn_name;
|
||||
let #catcher = #user_catcher_fn_name;
|
||||
#responder_stmt
|
||||
::rocket::response::Responder::respond_to(___responder, #req).await?
|
||||
});
|
||||
|
||||
|
|
|
@ -15,15 +15,23 @@ error[E0277]: the trait bound `bool: rocket::response::Responder<'_>` is not sat
|
|||
= note: required by `rocket::response::Responder::respond_to`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/catch_type_errors.rs:18:7
|
||||
--> $DIR/catch_type_errors.rs:17:1
|
||||
|
|
||||
17 | #[catch(404)]
|
||||
| ^^^^^^^^^^^^^ expected bool, found reference
|
||||
|
|
||||
= note: expected type `bool`
|
||||
found type `&'_b rocket::Request<'_>`
|
||||
|
||||
error[E0277]: the trait bound `usize: rocket::response::Responder<'_>` is not satisfied
|
||||
--> $DIR/catch_type_errors.rs:18:26
|
||||
|
|
||||
17 | #[catch(404)]
|
||||
| ------------- expected due to this
|
||||
18 | fn f3(_request: bool) -> usize {
|
||||
| ^^^^^^^^^^^^^^ expected `&rocket::Request<'_>`, found `bool`
|
||||
| ^^^^^ the trait `rocket::response::Responder<'_>` is not implemented for `usize`
|
||||
|
|
||||
= note: expected fn pointer `for<'r, 's> fn(&'r rocket::Request<'s>) -> _`
|
||||
found fn item `fn(bool) -> usize {f3}`
|
||||
= note: required by `rocket::response::Responder::respond_to`
|
||||
|
||||
error[E0277]: the trait bound `usize: rocket::response::Responder<'_>` is not satisfied
|
||||
--> $DIR/catch_type_errors.rs:24:12
|
||||
|
@ -33,7 +41,7 @@ error[E0277]: the trait bound `usize: rocket::response::Responder<'_>` is not sa
|
|||
|
|
||||
= note: required by `rocket::response::Responder::respond_to`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0277, E0308.
|
||||
For more information about an error, try `rustc --explain E0277`.
|
||||
|
|
Loading…
Reference in New Issue