1
0
Fork 0
mirror of https://github.com/tokio-rs/axum.git synced 2025-04-26 13:56:22 +02:00

Document the fact that debug_handler doesn't work within impl blocks ()

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
This commit is contained in:
Jesper Josefsson 2023-03-03 10:57:50 +02:00 committed by GitHub
parent 43883b8d9b
commit 67befbca52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<String>) {}
/// }
/// ```
///
/// 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<String>) {}
// | ^^^^ not found in this scope
/// ```
///
/// # Performance
///
/// This macro has no effect when compiled with the release profile. (eg. `cargo build --release`)