mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-09 00:00:12 +02:00
fix(axum-macros): use OptionalFromRequest for Option<T> fields (#3760)
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
use axum::{routing::get, Router};
|
||||
use axum_macros::FromRequest;
|
||||
|
||||
struct Payload;
|
||||
|
||||
#[derive(FromRequest)]
|
||||
struct Args {
|
||||
payload: Option<Payload>,
|
||||
}
|
||||
|
||||
async fn handler(_: Args) {}
|
||||
|
||||
fn main() {
|
||||
let _: Router = Router::new().route("/", get(handler));
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
error[E0277]: the trait bound `Payload: OptionalFromRequest<_, _>` is not satisfied
|
||||
--> tests/from_request/fail/option_without_optional_from_request.rs:8:21
|
||||
|
|
||||
8 | payload: Option<Payload>,
|
||||
| ^^^^^^^ unsatisfied trait bound
|
||||
|
|
||||
help: the trait `OptionalFromRequest<_, _>` is not implemented for `Payload`
|
||||
--> tests/from_request/fail/option_without_optional_from_request.rs:4:1
|
||||
|
|
||||
4 | struct Payload;
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: the trait `OptionalFromRequest<S>` is implemented for `Json<T>`
|
||||
--> $WORKSPACE/axum/src/json.rs
|
||||
|
|
||||
| / impl<T, S> OptionalFromRequest<S> for Json<T>
|
||||
| | where
|
||||
| | T: DeserializeOwned,
|
||||
| | S: Send + Sync,
|
||||
| |___________________^
|
||||
|
||||
error[E0277]: the trait bound `Payload: OptionalFromRequest<_, _>` is not satisfied
|
||||
--> tests/from_request/fail/option_without_optional_from_request.rs:8:14
|
||||
|
|
||||
8 | payload: Option<Payload>,
|
||||
| ^^^^^^^^^^^^^^^ unsatisfied trait bound
|
||||
|
|
||||
help: the trait `OptionalFromRequest<_, _>` is not implemented for `Payload`
|
||||
--> tests/from_request/fail/option_without_optional_from_request.rs:4:1
|
||||
|
|
||||
4 | struct Payload;
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: the trait `OptionalFromRequest<S>` is implemented for `Json<T>`
|
||||
--> $WORKSPACE/axum/src/json.rs
|
||||
|
|
||||
| / impl<T, S> OptionalFromRequest<S> for Json<T>
|
||||
| | where
|
||||
| | T: DeserializeOwned,
|
||||
| | S: Send + Sync,
|
||||
| |___________________^
|
||||
Reference in New Issue
Block a user