From eb8c24324408743cdc527fb74c822a95d215ca23 Mon Sep 17 00:00:00 2001 From: Bittrance Date: Tue, 16 Jul 2024 18:08:09 +0200 Subject: [PATCH 1/3] Emphasize that Request extractor goes last. --- axum/src/middleware/from_fn.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/axum/src/middleware/from_fn.rs b/axum/src/middleware/from_fn.rs index e4c44c74f5..3fbdb363c6 100644 --- a/axum/src/middleware/from_fn.rs +++ b/axum/src/middleware/from_fn.rs @@ -23,6 +23,8 @@ use tower_service::Service; /// 3. Take [`Next`](Next) as the final argument. /// 4. Return something that implements [`IntoResponse`]. /// +/// The last extractor (i.e. the second last argument) must be [`Request`] or some type implementing [`FromRequest`]. +/// /// Note that this function doesn't support extracting [`State`]. For that, use [`from_fn_with_state`]. /// /// # Example @@ -71,9 +73,7 @@ use tower_service::Service; /// async fn auth( /// // run the `HeaderMap` extractor /// headers: HeaderMap, -/// // you can also add more extractors here but the last -/// // extractor must implement `FromRequest` which -/// // `Request` does +/// // a `FromRequest` implementation must be the last extractor /// request: Request, /// next: Next, /// ) -> Result { From 9842593d901d1d2ae7311024c3b3d72b94f9d825 Mon Sep 17 00:00:00 2001 From: Bittrance Date: Thu, 18 Jul 2024 21:52:27 +0200 Subject: [PATCH 2/3] Improved from_fn docs as per mladedav suggestions. --- axum/src/middleware/from_fn.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/axum/src/middleware/from_fn.rs b/axum/src/middleware/from_fn.rs index 3fbdb363c6..97892dabe6 100644 --- a/axum/src/middleware/from_fn.rs +++ b/axum/src/middleware/from_fn.rs @@ -19,11 +19,10 @@ use tower_service::Service; /// `from_fn` requires the function given to /// /// 1. Be an `async fn`. -/// 2. Take one or more [extractors] as the first arguments. -/// 3. Take [`Next`](Next) as the final argument. -/// 4. Return something that implements [`IntoResponse`]. -/// -/// The last extractor (i.e. the second last argument) must be [`Request`] or some type implementing [`FromRequest`]. +/// 2. Take zero or more [`FromRequestParts`] extractors. +/// 3. Take exactly one [`FromRequest`] extractor as the second final argument. +/// 4. Take [`Next`](Next) as the final argument. +/// 5. Return something that implements [`IntoResponse`]. /// /// Note that this function doesn't support extracting [`State`]. For that, use [`from_fn_with_state`]. /// @@ -73,7 +72,9 @@ use tower_service::Service; /// async fn auth( /// // run the `HeaderMap` extractor /// headers: HeaderMap, -/// // a `FromRequest` implementation must be the last extractor +/// // you can also add more extractors here but the last +/// // extractor must implement `FromRequest` which +/// // `Request` does /// request: Request, /// next: Next, /// ) -> Result { From 02d7843e36b6696d7c2a9adb97c03bd61b7d5004 Mon Sep 17 00:00:00 2001 From: Bittrance Date: Fri, 19 Jul 2024 09:37:05 +0200 Subject: [PATCH 3/3] Simpler language in from_fn requirements docs Co-authored-by: Jonas Platte --- axum/src/middleware/from_fn.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/axum/src/middleware/from_fn.rs b/axum/src/middleware/from_fn.rs index 97892dabe6..3ed7a959d5 100644 --- a/axum/src/middleware/from_fn.rs +++ b/axum/src/middleware/from_fn.rs @@ -20,8 +20,8 @@ use tower_service::Service; /// /// 1. Be an `async fn`. /// 2. Take zero or more [`FromRequestParts`] extractors. -/// 3. Take exactly one [`FromRequest`] extractor as the second final argument. -/// 4. Take [`Next`](Next) as the final argument. +/// 3. Take exactly one [`FromRequest`] extractor as the second to last argument. +/// 4. Take [`Next`](Next) as the last argument. /// 5. Return something that implements [`IntoResponse`]. /// /// Note that this function doesn't support extracting [`State`]. For that, use [`from_fn_with_state`].