mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-08 00:00:24 +02:00
Make axum-debug handle more cases (#518)
* Make `axum-debug` handle more cases * Only just trybuild tests on stable * revert changes to hello-world example * Remove a bit of duplication * return error on generics * address review feedback * Support associated functions with receiver or returns `Self` * fix indentation
This commit is contained in:
@@ -4,8 +4,4 @@ error[E0277]: the trait bound `bool: FromRequest` is not satisfied
|
||||
4 | async fn handler(foo: bool) {}
|
||||
| ^^^^ the trait `FromRequest` is not implemented for `bool`
|
||||
|
|
||||
note: required by a bound in `handler::{closure#0}::debug_handler`
|
||||
--> tests/fail/argument_not_extractor.rs:4:23
|
||||
|
|
||||
4 | async fn handler(foo: bool) {}
|
||||
| ^^^^ required by this bound in `handler::{closure#0}::debug_handler`
|
||||
= help: see issue #48214
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
use axum_debug::debug_handler;
|
||||
|
||||
#[debug_handler(foo)]
|
||||
async fn handler() {}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: unexpected token
|
||||
--> tests/fail/attrs.rs:3:17
|
||||
|
|
||||
3 | #[debug_handler(foo)]
|
||||
| ^^^
|
||||
@@ -0,0 +1,23 @@
|
||||
use axum::{
|
||||
async_trait,
|
||||
extract::{FromRequest, RequestParts},
|
||||
};
|
||||
use axum_debug::debug_handler;
|
||||
|
||||
struct A;
|
||||
|
||||
#[async_trait]
|
||||
impl FromRequest for A {
|
||||
type Rejection = ();
|
||||
|
||||
async fn from_request(_req: &mut RequestParts) -> Result<Self, Self::Rejection> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl A {
|
||||
#[debug_handler]
|
||||
async fn handler(&mut self) {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Handlers must only take owned values
|
||||
--> tests/fail/extract_self_mut.rs:20:22
|
||||
|
|
||||
20 | async fn handler(&mut self) {}
|
||||
| ^^^^^^^^^
|
||||
@@ -0,0 +1,23 @@
|
||||
use axum::{
|
||||
async_trait,
|
||||
extract::{FromRequest, RequestParts},
|
||||
};
|
||||
use axum_debug::debug_handler;
|
||||
|
||||
struct A;
|
||||
|
||||
#[async_trait]
|
||||
impl FromRequest for A {
|
||||
type Rejection = ();
|
||||
|
||||
async fn from_request(_req: &mut RequestParts) -> Result<Self, Self::Rejection> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl A {
|
||||
#[debug_handler]
|
||||
async fn handler(&self) {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Handlers must only take owned values
|
||||
--> tests/fail/extract_self_ref.rs:20:22
|
||||
|
|
||||
20 | async fn handler(&self) {}
|
||||
| ^^^^^
|
||||
@@ -0,0 +1,6 @@
|
||||
use axum_debug::debug_handler;
|
||||
|
||||
#[debug_handler]
|
||||
async fn handler<T>() {}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,13 @@
|
||||
error: `#[axum_debug::debug_handler]` doesn't support generic functions
|
||||
--> tests/fail/generics.rs:4:17
|
||||
|
|
||||
4 | async fn handler<T>() {}
|
||||
| ^^^
|
||||
|
||||
error[E0282]: type annotations needed
|
||||
--> tests/fail/generics.rs:4:10
|
||||
|
|
||||
4 | async fn handler<T>() {}
|
||||
| ----- ^^^^^^^ cannot infer type for type parameter `T` declared on the function `handler`
|
||||
| |
|
||||
| consider giving `future` a type
|
||||
@@ -1,4 +1,4 @@
|
||||
error: handlers must be async functions
|
||||
error: Handlers must be `async fn`s
|
||||
--> tests/fail/not_async.rs:4:1
|
||||
|
|
||||
4 | fn handler() {}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
error: future cannot be sent between threads safely
|
||||
--> tests/fail/not_send.rs:4:10
|
||||
--> tests/fail/not_send.rs:4:1
|
||||
|
|
||||
4 | async fn handler() {
|
||||
| ^^^^^^^ future returned by `handler` is not `Send`
|
||||
| ^^^^^ future returned by `handler` is not `Send`
|
||||
|
|
||||
= help: within `impl Future`, the trait `Send` is not implemented for `Rc<()>`
|
||||
note: future is not `Send` as this value is used across an await
|
||||
@@ -14,8 +14,8 @@ note: future is not `Send` as this value is used across an await
|
||||
| ^^^^^^^^^^^^^^ await occurs here, with `rc` maybe used later
|
||||
7 | }
|
||||
| - `rc` is later dropped here
|
||||
note: required by a bound in `handler::{closure#0}::debug_handler`
|
||||
--> tests/fail/not_send.rs:4:10
|
||||
note: required by a bound in `check`
|
||||
--> tests/fail/not_send.rs:4:1
|
||||
|
|
||||
4 | async fn handler() {
|
||||
| ^^^^^^^ required by this bound in `handler::{closure#0}::debug_handler`
|
||||
| ^^^^^ required by this bound in `check`
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
error: `#[debug_handler]` is not supported on methods
|
||||
--> tests/fail/self_receiver.rs:17:22
|
||||
|
|
||||
17 | async fn handler(self) {}
|
||||
| ^^^^
|
||||
@@ -1,5 +1,4 @@
|
||||
error: too many extractors. 16 extractors are allowed
|
||||
note: you can nest extractors like "a: (Extractor, Extractor), b: (Extractor, Extractor)"
|
||||
error: Handlers cannot take more than 16 arguments. Use `(a, b): (ExtractorA, ExtractorA)` to further nest extractors
|
||||
--> tests/fail/too_many_extractors.rs:5:5
|
||||
|
|
||||
5 | / e1: String,
|
||||
|
||||
@@ -4,8 +4,8 @@ error[E0277]: the trait bound `bool: IntoResponse` is not satisfied
|
||||
4 | async fn handler() -> bool {
|
||||
| ^^^^ the trait `IntoResponse` is not implemented for `bool`
|
||||
|
|
||||
note: required by a bound in `handler::{closure#0}::debug_handler`
|
||||
note: required by a bound in `__axum_debug_check_handler_into_response::{closure#0}::check`
|
||||
--> tests/fail/wrong_return_type.rs:4:23
|
||||
|
|
||||
4 | async fn handler() -> bool {
|
||||
| ^^^^ required by this bound in `handler::{closure#0}::debug_handler`
|
||||
| ^^^^ required by this bound in `__axum_debug_check_handler_into_response::{closure#0}::check`
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
use axum_debug::debug_handler;
|
||||
|
||||
struct A;
|
||||
|
||||
impl A {
|
||||
#[debug_handler]
|
||||
async fn handler() {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,9 @@
|
||||
use axum_debug::debug_handler;
|
||||
use std::future::Future;
|
||||
|
||||
#[debug_handler]
|
||||
fn handler() -> impl Future<Output = ()> {
|
||||
async {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,9 @@
|
||||
use axum_debug::debug_handler;
|
||||
use axum::response::IntoResponse;
|
||||
|
||||
#[debug_handler]
|
||||
async fn handler() -> impl IntoResponse {
|
||||
"hi!"
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,9 @@
|
||||
use axum_debug::debug_handler;
|
||||
|
||||
#[debug_handler]
|
||||
async fn handler(mut foo: String) -> String {
|
||||
foo += "bar";
|
||||
foo
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,9 @@
|
||||
use axum_debug::debug_handler;
|
||||
use std::future::{Ready, ready};
|
||||
|
||||
#[debug_handler]
|
||||
fn handler() -> Ready<()> {
|
||||
ready(())
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,27 @@
|
||||
use axum::{
|
||||
body::{Bytes, Full},
|
||||
http::Response,
|
||||
response::IntoResponse,
|
||||
};
|
||||
use axum_debug::debug_handler;
|
||||
use std::convert::Infallible;
|
||||
|
||||
struct A;
|
||||
|
||||
impl A {
|
||||
#[debug_handler]
|
||||
async fn handler() -> Self {
|
||||
A
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoResponse for A {
|
||||
type Body = Full<Bytes>;
|
||||
type BodyError = Infallible;
|
||||
|
||||
fn into_response(self) -> Response<Self::Body> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -1,5 +1,8 @@
|
||||
use axum::{
|
||||
async_trait,
|
||||
extract::{FromRequest, RequestParts},
|
||||
};
|
||||
use axum_debug::debug_handler;
|
||||
use axum::{async_trait, extract::{FromRequest, RequestParts}};
|
||||
|
||||
struct A;
|
||||
|
||||
Reference in New Issue
Block a user