2022-08-22 15:34:17 +02:00
|
|
|
use axum::{async_trait, extract::FromRequestParts, http::request::Parts, response::IntoResponse};
|
2022-01-26 23:27:22 +01:00
|
|
|
use axum_macros::debug_handler;
|
2021-12-04 18:24:58 +01:00
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
fn concrete_future() -> std::future::Ready<Result<impl IntoResponse, ()>> {
|
|
|
|
std::future::ready(Ok(()))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
fn impl_future() -> impl std::future::Future<Output = Result<impl IntoResponse, ()>> {
|
|
|
|
std::future::ready(Ok(()))
|
|
|
|
}
|
|
|
|
|
|
|
|
// === no args ===
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
async fn handler_no_arg_one() -> Result<impl IntoResponse, ()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
async fn handler_no_arg_two() -> Result<(), impl IntoResponse> {
|
|
|
|
Err(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
async fn handler_no_arg_three() -> Result<impl IntoResponse, impl IntoResponse> {
|
|
|
|
Ok::<_, ()>(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
async fn handler_no_arg_four() -> Result<impl IntoResponse, impl IntoResponse> {
|
|
|
|
Err::<(), _>(())
|
|
|
|
}
|
|
|
|
|
|
|
|
// === args ===
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
async fn handler_one(foo: String) -> Result<impl IntoResponse, ()> {
|
|
|
|
dbg!(foo);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
async fn handler_two(foo: String) -> Result<(), impl IntoResponse> {
|
|
|
|
dbg!(foo);
|
|
|
|
Err(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
async fn handler_three(foo: String) -> Result<impl IntoResponse, impl IntoResponse> {
|
|
|
|
dbg!(foo);
|
|
|
|
Ok::<_, ()>(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
async fn handler_four(foo: String) -> Result<impl IntoResponse, impl IntoResponse> {
|
|
|
|
dbg!(foo);
|
|
|
|
Err::<(), _>(())
|
|
|
|
}
|
|
|
|
|
|
|
|
// === no args with receiver ===
|
|
|
|
|
|
|
|
struct A;
|
|
|
|
|
|
|
|
impl A {
|
|
|
|
#[debug_handler]
|
|
|
|
async fn handler_no_arg_one(self) -> Result<impl IntoResponse, ()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
async fn handler_no_arg_two(self) -> Result<(), impl IntoResponse> {
|
|
|
|
Err(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
async fn handler_no_arg_three(self) -> Result<impl IntoResponse, impl IntoResponse> {
|
|
|
|
Ok::<_, ()>(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
async fn handler_no_arg_four(self) -> Result<impl IntoResponse, impl IntoResponse> {
|
|
|
|
Err::<(), _>(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// === args with receiver ===
|
|
|
|
|
|
|
|
impl A {
|
|
|
|
#[debug_handler]
|
|
|
|
async fn handler_one(self, foo: String) -> Result<impl IntoResponse, ()> {
|
|
|
|
dbg!(foo);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
async fn handler_two(self, foo: String) -> Result<(), impl IntoResponse> {
|
|
|
|
dbg!(foo);
|
|
|
|
Err(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
async fn handler_three(self, foo: String) -> Result<impl IntoResponse, impl IntoResponse> {
|
|
|
|
dbg!(foo);
|
|
|
|
Ok::<_, ()>(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
async fn handler_four(self, foo: String) -> Result<impl IntoResponse, impl IntoResponse> {
|
|
|
|
dbg!(foo);
|
|
|
|
Err::<(), _>(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait]
|
2022-08-22 15:34:17 +02:00
|
|
|
impl<S> FromRequestParts<S> for A
|
2021-12-04 18:24:58 +01:00
|
|
|
where
|
2022-08-17 22:08:24 +02:00
|
|
|
S: Send + Sync,
|
2021-12-04 18:24:58 +01:00
|
|
|
{
|
|
|
|
type Rejection = ();
|
|
|
|
|
2022-08-22 15:34:17 +02:00
|
|
|
async fn from_request_parts(_parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
|
2021-12-04 18:24:58 +01:00
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|