From 67befbca520c688f5953b6f40ec265e7eae67176 Mon Sep 17 00:00:00 2001 From: Jesper Josefsson Date: Fri, 3 Mar 2023 10:57:50 +0200 Subject: [PATCH] Document the fact that `debug_handler` doesn't work within impl blocks (#1800) Co-authored-by: David Pedersen --- axum-macros/src/lib.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/axum-macros/src/lib.rs b/axum-macros/src/lib.rs index 78575390..f4582607 100644 --- a/axum-macros/src/lib.rs +++ b/axum-macros/src/lib.rs @@ -540,6 +540,32 @@ pub fn derive_from_request_parts(item: TokenStream) -> TokenStream { /// } /// ``` /// +/// # Limitations +/// +/// This macro does not work for associated functions — functions defined in an `impl` block that +/// don't take `self`: +/// +/// ```compile_fail +/// use axum::{debug_handler, extract::Path}; +/// +/// struct App {} +/// +/// impl App { +/// #[debug_handler] +/// async fn handler(Path(_): Path) {} +/// } +/// ``` +/// +/// This will yield an error similar to this: +/// +/// ```text +/// error[E0425]: cannot find function `__axum_macros_check_handler_0_from_request_check` in this scope +// --> src/main.rs:xx:xx +// | +// xx | pub async fn handler(Path(_): Path) {} +// | ^^^^ not found in this scope +/// ``` +/// /// # Performance /// /// This macro has no effect when compiled with the release profile. (eg. `cargo build --release`)