mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-25 00:00:23 +02:00
Only allow last extractor to mutate the request (#1272)
* Only allow last extractor to mutate the request * Change `FromRequest` and add `FromRequestParts` trait (#1275) * Add `Once`/`Mut` type parameter for `FromRequest` and `RequestParts` * 🪄 * split traits * `FromRequest` for tuples * Remove `BodyAlreadyExtracted` * don't need fully qualified path * don't export `Once` and `Mut` * remove temp tests * depend on axum again Co-authored-by: Jonas Platte <[email protected]> * Port `Handler` and most extractors (#1277) * Port `Handler` and most extractors * Put `M` inside `Handler` impls, not trait itself * comment out tuples for now * fix lints * Reorder arguments to `Handler` (#1281) I think `Request<B>, Arc<S>` is better since its consistent with `FromRequest` and `FromRequestParts`. * Port most things in axum-extra (#1282) * Port `#[derive(TypedPath)]` and `#[debug_handler]` (#1283) * port #[derive(TypedPath)] * wip: #[debug_handler] * fix #[debug_handler] * don't need itertools * also require `Send` * update expected error * support fully qualified `self` * Implement FromRequest[Parts] for tuples (#1286) * Port docs for axum and axum-core (#1285) * Port axum-extra (#1287) * Port axum-extra * Update axum-core/Cargo.toml Co-authored-by: Jonas Platte <[email protected]> * remove `impl FromRequest for Either*` Co-authored-by: Jonas Platte <[email protected]> * New FromRequest[Parts] trait cleanup (#1288) * Make private module truly private again * Simplify tuple FromRequest implementation * Port `#[derive(FromRequest)]` (#1289) * fix tests * fix docs * revert examples * fix docs link * fix intra docs links * Port examples (#1291) * Document wrapping other extractors (#1292) * axum-extra doesn't need to depend on axum-core (#1294) Missed this in https://github.com/tokio-rs/axum/pull/1287 * Add `FromRequest` changes to changelogs (#1293) * Update changelog * Remove default type for `S` in `Handler` * Clarify which types have default types for `S` * Apply suggestions from code review Co-authored-by: Jonas Platte <[email protected]> Co-authored-by: Jonas Platte <[email protected]> * remove unused import * Rename `Mut` and `Once` (#1296) * fix trybuild expected output Co-authored-by: Jonas Platte <[email protected]>
This commit is contained in:
co-authored by
Jonas Platte
parent
f1769e5134
commit
be624306f4
@@ -1,17 +1,22 @@
|
||||
error[E0277]: the trait bound `bool: FromRequest<(), Body>` is not satisfied
|
||||
error[E0277]: the trait bound `bool: FromRequestParts<()>` is not satisfied
|
||||
--> tests/debug_handler/fail/argument_not_extractor.rs:4:23
|
||||
|
|
||||
4 | async fn handler(foo: bool) {}
|
||||
| ^^^^ the trait `FromRequest<(), Body>` is not implemented for `bool`
|
||||
| ^^^^ the trait `FromRequestParts<()>` is not implemented for `bool`
|
||||
|
|
||||
= help: the following other types implement trait `FromRequest<S, B>`:
|
||||
<() as FromRequest<S, B>>
|
||||
<(T1, T2) as FromRequest<S, B>>
|
||||
<(T1, T2, T3) as FromRequest<S, B>>
|
||||
<(T1, T2, T3, T4) as FromRequest<S, B>>
|
||||
<(T1, T2, T3, T4, T5) as FromRequest<S, B>>
|
||||
<(T1, T2, T3, T4, T5, T6) as FromRequest<S, B>>
|
||||
<(T1, T2, T3, T4, T5, T6, T7) as FromRequest<S, B>>
|
||||
<(T1, T2, T3, T4, T5, T6, T7, T8) as FromRequest<S, B>>
|
||||
and 34 others
|
||||
= help: see issue #48214
|
||||
= help: the following other types implement trait `FromRequestParts<S>`:
|
||||
<() as FromRequestParts<S>>
|
||||
<(T1, T2) as FromRequestParts<S>>
|
||||
<(T1, T2, T3) as FromRequestParts<S>>
|
||||
<(T1, T2, T3, T4) as FromRequestParts<S>>
|
||||
<(T1, T2, T3, T4, T5) as FromRequestParts<S>>
|
||||
<(T1, T2, T3, T4, T5, T6) as FromRequestParts<S>>
|
||||
<(T1, T2, T3, T4, T5, T6, T7) as FromRequestParts<S>>
|
||||
<(T1, T2, T3, T4, T5, T6, T7, T8) as FromRequestParts<S>>
|
||||
and 26 others
|
||||
= note: required because of the requirements on the impl of `FromRequest<(), Body, axum_core::extract::private::ViaParts>` for `bool`
|
||||
note: required by a bound in `__axum_macros_check_handler_0_from_request_check`
|
||||
--> tests/debug_handler/fail/argument_not_extractor.rs:4:23
|
||||
|
|
||||
4 | async fn handler(foo: bool) {}
|
||||
| ^^^^ required by this bound in `__axum_macros_check_handler_0_from_request_check`
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use axum::{
|
||||
async_trait,
|
||||
extract::{FromRequest, RequestParts},
|
||||
extract::FromRequest,
|
||||
http::Request,
|
||||
};
|
||||
use axum_macros::debug_handler;
|
||||
|
||||
@@ -9,12 +10,12 @@ struct A;
|
||||
#[async_trait]
|
||||
impl<S, B> FromRequest<S, B> for A
|
||||
where
|
||||
B: Send,
|
||||
B: Send + 'static,
|
||||
S: Send + Sync,
|
||||
{
|
||||
type Rejection = ();
|
||||
|
||||
async fn from_request(_req: &mut RequestParts<S, B>) -> Result<Self, Self::Rejection> {
|
||||
async fn from_request(_req: Request<B>, _state: &S) -> Result<Self, Self::Rejection> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error: Handlers must only take owned values
|
||||
--> tests/debug_handler/fail/extract_self_mut.rs:24:22
|
||||
--> tests/debug_handler/fail/extract_self_mut.rs:25:22
|
||||
|
|
||||
24 | async fn handler(&mut self) {}
|
||||
25 | async fn handler(&mut self) {}
|
||||
| ^^^^^^^^^
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use axum::{
|
||||
async_trait,
|
||||
extract::{FromRequest, RequestParts},
|
||||
extract::FromRequest,
|
||||
http::Request,
|
||||
};
|
||||
use axum_macros::debug_handler;
|
||||
|
||||
@@ -9,12 +10,12 @@ struct A;
|
||||
#[async_trait]
|
||||
impl<S, B> FromRequest<S, B> for A
|
||||
where
|
||||
B: Send,
|
||||
B: Send + 'static,
|
||||
S: Send + Sync,
|
||||
{
|
||||
type Rejection = ();
|
||||
|
||||
async fn from_request(_req: &mut RequestParts<S, B>) -> Result<Self, Self::Rejection> {
|
||||
async fn from_request(_req: Request<B>, _state: &S) -> Result<Self, Self::Rejection> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error: Handlers must only take owned values
|
||||
--> tests/debug_handler/fail/extract_self_ref.rs:24:22
|
||||
--> tests/debug_handler/fail/extract_self_ref.rs:25:22
|
||||
|
|
||||
24 | async fn handler(&self) {}
|
||||
25 | async fn handler(&self) {}
|
||||
| ^^^^^
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
use axum_macros::debug_handler;
|
||||
use axum::body::Bytes;
|
||||
|
||||
#[debug_handler]
|
||||
async fn handler(_: String, _: Bytes) {}
|
||||
|
||||
fn main() {}
|
||||
@@ -1,11 +0,0 @@
|
||||
error: Only one body extractor can be applied
|
||||
--> tests/debug_handler/fail/multiple_body_extractors.rs:5:18
|
||||
|
|
||||
5 | async fn handler(_: String, _: Bytes) {}
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: Only one body extractor can be applied
|
||||
--> tests/debug_handler/fail/multiple_body_extractors.rs:5:29
|
||||
|
|
||||
5 | async fn handler(_: String, _: Bytes) {}
|
||||
| ^^^^^^^^
|
||||
@@ -1,7 +0,0 @@
|
||||
use axum::{body::Body, extract::Extension, http::Request};
|
||||
use axum_macros::debug_handler;
|
||||
|
||||
#[debug_handler]
|
||||
async fn handler(_: Request<Body>, _: Extension<String>) {}
|
||||
|
||||
fn main() {}
|
||||
@@ -1,5 +0,0 @@
|
||||
error: `Request` extractor should always be last
|
||||
--> tests/debug_handler/fail/request_not_last.rs:5:18
|
||||
|
|
||||
5 | async fn handler(_: Request<Body>, _: Extension<String>) {}
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
@@ -13,7 +13,7 @@ error[E0277]: the trait bound `bool: IntoResponse` is not satisfied
|
||||
(Response<()>, T1, T2, R)
|
||||
(Response<()>, T1, T2, T3, R)
|
||||
(Response<()>, T1, T2, T3, T4, R)
|
||||
and 123 others
|
||||
and 122 others
|
||||
note: required by a bound in `__axum_macros_check_handler_into_response::{closure#0}::check`
|
||||
--> tests/debug_handler/fail/wrong_return_type.rs:4:23
|
||||
|
|
||||
|
||||
Reference in New Issue
Block a user