mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-27 00:00:24 +02:00
Support changing state type in #[debug_handler] (#1271)
* support setting body type for #[debug_handler] * Use lookahead1 to give better errors and detect duplicate arguments * fix docs link
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
use axum_macros::debug_handler;
|
||||
use axum::extract::State;
|
||||
|
||||
#[debug_handler]
|
||||
async fn handler(_: State<AppState>) {}
|
||||
|
||||
#[debug_handler]
|
||||
async fn handler_2(_: axum::extract::State<AppState>) {}
|
||||
|
||||
#[debug_handler]
|
||||
async fn handler_3(
|
||||
_: axum::extract::State<AppState>,
|
||||
_: axum::extract::State<AppState>,
|
||||
) {}
|
||||
|
||||
#[debug_handler]
|
||||
async fn handler_4(
|
||||
_: State<AppState>,
|
||||
_: State<AppState>,
|
||||
) {}
|
||||
|
||||
#[debug_handler]
|
||||
async fn handler_5(
|
||||
_: axum::extract::State<AppState>,
|
||||
_: State<AppState>,
|
||||
) {}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct AppState;
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,27 @@
|
||||
use axum_macros::debug_handler;
|
||||
use axum::extract::{FromRef, FromRequest, RequestParts};
|
||||
use axum::async_trait;
|
||||
|
||||
#[debug_handler(state = AppState)]
|
||||
async fn handler(_: A) {}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct AppState;
|
||||
|
||||
struct A;
|
||||
|
||||
#[async_trait]
|
||||
impl<S, B> FromRequest<S, B> for A
|
||||
where
|
||||
B: Send,
|
||||
S: Send + Sync,
|
||||
AppState: FromRef<S>,
|
||||
{
|
||||
type Rejection = ();
|
||||
|
||||
async fn from_request(_req: &mut RequestParts<S, B>) -> Result<Self, Self::Rejection> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,10 @@
|
||||
use axum_macros::debug_handler;
|
||||
use axum::{body::BoxBody, extract::State, http::Request};
|
||||
|
||||
#[debug_handler(state = AppState, body = BoxBody)]
|
||||
async fn handler(_: State<AppState>, _: Request<BoxBody>) {}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct AppState;
|
||||
|
||||
fn main() {}
|
||||
Reference in New Issue
Block a user