mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-08 00:00:24 +02:00
Support using a different rejection for #[derive(FromRequest)] (#1256)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
error: `#[derive(FromRequest)] doesn't support generics
|
||||
--> tests/from_request/fail/generic.rs:4:17
|
||||
error: #[derive(FromRequest)] only supports generics on tuple structs that have exactly one field of the generic type
|
||||
--> tests/from_request/fail/generic.rs:4:21
|
||||
|
|
||||
4 | struct Extractor<T>(Option<T>);
|
||||
| ^^^
|
||||
| ^^^^^^^^^
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
use axum::{body::Body, routing::get, Extension, Router};
|
||||
use axum_macros::FromRequest;
|
||||
|
||||
#[derive(FromRequest, Clone)]
|
||||
struct Extractor<T>(T);
|
||||
|
||||
async fn foo(_: Extractor<()>) {}
|
||||
|
||||
fn main() {
|
||||
Router::<Body>::new().route("/", get(foo));
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
error: #[derive(FromRequest)] only supports generics when used with #[from_request(via)]
|
||||
--> tests/from_request/fail/generic_without_via.rs:5:18
|
||||
|
|
||||
5 | struct Extractor<T>(T);
|
||||
| ^
|
||||
|
||||
warning: unused import: `Extension`
|
||||
--> tests/from_request/fail/generic_without_via.rs:1:38
|
||||
|
|
||||
1 | use axum::{body::Body, routing::get, Extension, Router};
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(unused_imports)]` on by default
|
||||
|
||||
error[E0277]: the trait bound `fn(Extractor<()>) -> impl Future<Output = ()> {foo}: Handler<_, _>` is not satisfied
|
||||
--> tests/from_request/fail/generic_without_via.rs:10:42
|
||||
|
|
||||
10 | Router::<Body>::new().route("/", get(foo));
|
||||
| --- ^^^ the trait `Handler<_, _>` is not implemented for `fn(Extractor<()>) -> impl Future<Output = ()> {foo}`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the trait `Handler<T, ReqBody>` is implemented for `Layered<S, T>`
|
||||
note: required by a bound in `axum::routing::get`
|
||||
--> $WORKSPACE/axum/src/routing/method_routing.rs
|
||||
|
|
||||
| top_level_handler_fn!(get, GET);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `axum::routing::get`
|
||||
= note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
@@ -0,0 +1,12 @@
|
||||
use axum::{body::Body, routing::get, Extension, Router};
|
||||
use axum_macros::FromRequest;
|
||||
|
||||
#[derive(FromRequest, Clone)]
|
||||
#[from_request(rejection(Foo))]
|
||||
struct Extractor<T>(T);
|
||||
|
||||
async fn foo(_: Extractor<()>) {}
|
||||
|
||||
fn main() {
|
||||
Router::<Body>::new().route("/", get(foo));
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
error: #[derive(FromRequest)] only supports generics when used with #[from_request(via)]
|
||||
--> tests/from_request/fail/generic_without_via_rejection.rs:6:18
|
||||
|
|
||||
6 | struct Extractor<T>(T);
|
||||
| ^
|
||||
|
||||
warning: unused import: `Extension`
|
||||
--> tests/from_request/fail/generic_without_via_rejection.rs:1:38
|
||||
|
|
||||
1 | use axum::{body::Body, routing::get, Extension, Router};
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(unused_imports)]` on by default
|
||||
|
||||
error[E0277]: the trait bound `fn(Extractor<()>) -> impl Future<Output = ()> {foo}: Handler<_, _>` is not satisfied
|
||||
--> tests/from_request/fail/generic_without_via_rejection.rs:11:42
|
||||
|
|
||||
11 | Router::<Body>::new().route("/", get(foo));
|
||||
| --- ^^^ the trait `Handler<_, _>` is not implemented for `fn(Extractor<()>) -> impl Future<Output = ()> {foo}`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the trait `Handler<T, ReqBody>` is implemented for `Layered<S, T>`
|
||||
note: required by a bound in `axum::routing::get`
|
||||
--> $WORKSPACE/axum/src/routing/method_routing.rs
|
||||
|
|
||||
| top_level_handler_fn!(get, GET);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `axum::routing::get`
|
||||
= note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
@@ -0,0 +1,12 @@
|
||||
use axum::{body::Body, routing::get, Extension, Router};
|
||||
use axum_macros::FromRequest;
|
||||
|
||||
#[derive(FromRequest, Clone)]
|
||||
#[from_request(rejection_derive(!Error))]
|
||||
struct Extractor<T>(T);
|
||||
|
||||
async fn foo(_: Extractor<()>) {}
|
||||
|
||||
fn main() {
|
||||
Router::<Body>::new().route("/", get(foo));
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
error: #[derive(FromRequest)] only supports generics when used with #[from_request(via)]
|
||||
--> tests/from_request/fail/generic_without_via_rejection_derive.rs:6:18
|
||||
|
|
||||
6 | struct Extractor<T>(T);
|
||||
| ^
|
||||
|
||||
warning: unused import: `Extension`
|
||||
--> tests/from_request/fail/generic_without_via_rejection_derive.rs:1:38
|
||||
|
|
||||
1 | use axum::{body::Body, routing::get, Extension, Router};
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(unused_imports)]` on by default
|
||||
|
||||
error[E0277]: the trait bound `fn(Extractor<()>) -> impl Future<Output = ()> {foo}: Handler<_, _>` is not satisfied
|
||||
--> tests/from_request/fail/generic_without_via_rejection_derive.rs:11:42
|
||||
|
|
||||
11 | Router::<Body>::new().route("/", get(foo));
|
||||
| --- ^^^ the trait `Handler<_, _>` is not implemented for `fn(Extractor<()>) -> impl Future<Output = ()> {foo}`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the trait `Handler<T, ReqBody>` is implemented for `Layered<S, T>`
|
||||
note: required by a bound in `axum::routing::get`
|
||||
--> $WORKSPACE/axum/src/routing/method_routing.rs
|
||||
|
|
||||
| top_level_handler_fn!(get, GET);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `axum::routing::get`
|
||||
= note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
@@ -0,0 +1,33 @@
|
||||
use axum::{
|
||||
extract::rejection::ExtensionRejection,
|
||||
response::{IntoResponse, Response},
|
||||
routing::get,
|
||||
Router,
|
||||
};
|
||||
use axum_macros::FromRequest;
|
||||
|
||||
fn main() {
|
||||
let _: Router = Router::new().route("/", get(handler).post(handler_result));
|
||||
}
|
||||
|
||||
async fn handler(_: MyExtractor) {}
|
||||
|
||||
async fn handler_result(_: Result<MyExtractor, MyRejection>) {}
|
||||
|
||||
#[derive(FromRequest, Clone)]
|
||||
#[from_request(rejection(MyRejection))]
|
||||
enum MyExtractor {}
|
||||
|
||||
struct MyRejection {}
|
||||
|
||||
impl From<ExtensionRejection> for MyRejection {
|
||||
fn from(_: ExtensionRejection) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoResponse for MyRejection {
|
||||
fn into_response(self) -> Response {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
error: cannot use `rejection` without `via`
|
||||
--> tests/from_request/fail/override_rejection_on_enum_without_via.rs:18:26
|
||||
|
|
||||
18 | #[from_request(rejection(MyRejection))]
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error[E0277]: the trait bound `fn(MyExtractor) -> impl Future<Output = ()> {handler}: Handler<_, _>` is not satisfied
|
||||
--> tests/from_request/fail/override_rejection_on_enum_without_via.rs:10:50
|
||||
|
|
||||
10 | let _: Router = Router::new().route("/", get(handler).post(handler_result));
|
||||
| --- ^^^^^^^ the trait `Handler<_, _>` is not implemented for `fn(MyExtractor) -> impl Future<Output = ()> {handler}`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the trait `Handler<T, ReqBody>` is implemented for `Layered<S, T>`
|
||||
note: required by a bound in `axum::routing::get`
|
||||
--> $WORKSPACE/axum/src/routing/method_routing.rs
|
||||
|
|
||||
| top_level_handler_fn!(get, GET);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `axum::routing::get`
|
||||
= note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0277]: the trait bound `fn(Result<MyExtractor, MyRejection>) -> impl Future<Output = ()> {handler_result}: Handler<_, _>` is not satisfied
|
||||
--> tests/from_request/fail/override_rejection_on_enum_without_via.rs:10:64
|
||||
|
|
||||
10 | let _: Router = Router::new().route("/", get(handler).post(handler_result));
|
||||
| ---- ^^^^^^^^^^^^^^ the trait `Handler<_, _>` is not implemented for `fn(Result<MyExtractor, MyRejection>) -> impl Future<Output = ()> {handler_result}`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the trait `Handler<T, ReqBody>` is implemented for `Layered<S, T>`
|
||||
note: required by a bound in `MethodRouter::<B>::post`
|
||||
--> $WORKSPACE/axum/src/routing/method_routing.rs
|
||||
|
|
||||
| chained_handler_fn!(post, POST);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `MethodRouter::<B>::post`
|
||||
= note: this error originates in the macro `chained_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
@@ -1,4 +1,4 @@
|
||||
error: expected `via` or `rejection_derive`
|
||||
error: expected one of: `via`, `rejection_derive`, `rejection`
|
||||
--> tests/from_request/fail/unknown_attr_container.rs:4:16
|
||||
|
|
||||
4 | #[from_request(foo)]
|
||||
|
||||
Reference in New Issue
Block a user