Move axum-debug into axum-macros (#724)

* Move axum-debug into axum-macros

* fix ref to axum-macros in changelog

* Apply suggestions from code review

Co-authored-by: Jonas Platte <[email protected]>

Co-authored-by: Jonas Platte <[email protected]>
This commit is contained in:
David Pedersen
2022-01-26 23:27:22 +01:00
committed by GitHub
co-authored by Jonas Platte
parent b1283e9708
commit f6fc5ed80c
60 changed files with 492 additions and 217 deletions
@@ -0,0 +1,6 @@
use axum_macros::debug_handler;
#[debug_handler]
async fn handler(foo: bool) {}
fn main() {}
@@ -0,0 +1,7 @@
error[E0277]: the trait bound `bool: FromRequest<Body>` is not satisfied
--> tests/debug_handler/fail/argument_not_extractor.rs:4:23
|
4 | async fn handler(foo: bool) {}
| ^^^^ the trait `FromRequest<Body>` is not implemented for `bool`
|
= help: see issue #48214
@@ -0,0 +1,26 @@
use axum::{
async_trait,
extract::{FromRequest, RequestParts},
};
use axum_macros::debug_handler;
struct A;
#[async_trait]
impl<B> FromRequest<B> for A
where
B: Send + 'static,
{
type Rejection = ();
async fn from_request(_req: &mut RequestParts<B>) -> 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/debug_handler/fail/extract_self_mut.rs:23:22
|
23 | async fn handler(&mut self) {}
| ^^^^^^^^^
@@ -0,0 +1,26 @@
use axum::{
async_trait,
extract::{FromRequest, RequestParts},
};
use axum_macros::debug_handler;
struct A;
#[async_trait]
impl<B> FromRequest<B> for A
where
B: Send + 'static,
{
type Rejection = ();
async fn from_request(_req: &mut RequestParts<B>) -> 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/debug_handler/fail/extract_self_ref.rs:23:22
|
23 | async fn handler(&self) {}
| ^^^^^
@@ -0,0 +1,6 @@
use axum_macros::debug_handler;
#[debug_handler]
async fn handler<T>() {}
fn main() {}
@@ -0,0 +1,13 @@
error: `#[axum_macros::debug_handler]` doesn't support generic functions
--> tests/debug_handler/fail/generics.rs:4:17
|
4 | async fn handler<T>() {}
| ^^^
error[E0282]: type annotations needed
--> tests/debug_handler/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
@@ -0,0 +1,6 @@
use axum_macros::debug_handler;
#[debug_handler(foo)]
async fn handler() {}
fn main() {}
@@ -0,0 +1,5 @@
error: unknown argument
--> tests/debug_handler/fail/invalid_attrs.rs:3:17
|
3 | #[debug_handler(foo)]
| ^^^
@@ -0,0 +1,6 @@
use axum_macros::debug_handler;
#[debug_handler]
struct A;
fn main() {}
@@ -0,0 +1,5 @@
error: expected `fn`
--> tests/debug_handler/fail/not_a_function.rs:4:1
|
4 | struct A;
| ^^^^^^
@@ -0,0 +1,6 @@
use axum_macros::debug_handler;
#[debug_handler]
fn handler() {}
fn main() {}
@@ -0,0 +1,5 @@
error: Handlers must be `async fn`s
--> tests/debug_handler/fail/not_async.rs:4:1
|
4 | fn handler() {}
| ^^
@@ -0,0 +1,9 @@
use axum_macros::debug_handler;
#[debug_handler]
async fn handler() {
let rc = std::rc::Rc::new(());
async {}.await;
}
fn main() {}
@@ -0,0 +1,21 @@
error: future cannot be sent between threads safely
--> tests/debug_handler/fail/not_send.rs:4:1
|
4 | async fn handler() {
| ^^^^^ future returned by `handler` is not `Send`
|
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `Rc<()>`
note: future is not `Send` as this value is used across an await
--> tests/debug_handler/fail/not_send.rs:6:5
|
5 | let rc = std::rc::Rc::new(());
| -- has type `Rc<()>` which is not `Send`
6 | async {}.await;
| ^^^^^^^^^^^^^^ await occurs here, with `rc` maybe used later
7 | }
| - `rc` is later dropped here
note: required by a bound in `check`
--> tests/debug_handler/fail/not_send.rs:4:1
|
4 | async fn handler() {
| ^^^^^ required by this bound in `check`
@@ -0,0 +1,24 @@
use axum_macros::debug_handler;
#[debug_handler]
async fn handler(
e1: String,
e2: String,
e3: String,
e4: String,
e5: String,
e6: String,
e7: String,
e8: String,
e9: String,
e10: String,
e11: String,
e12: String,
e13: String,
e14: String,
e15: String,
e16: String,
e17: String,
) {}
fn main() {}
@@ -0,0 +1,11 @@
error: Handlers cannot take more than 16 arguments. Use `(a, b): (ExtractorA, ExtractorA)` to further nest extractors
--> tests/debug_handler/fail/too_many_extractors.rs:5:5
|
5 | / e1: String,
6 | | e2: String,
7 | | e3: String,
8 | | e4: String,
... |
20 | | e16: String,
21 | | e17: String,
| |________________^
@@ -0,0 +1,8 @@
use axum_macros::debug_handler;
#[debug_handler]
async fn handler() -> bool {
false
}
fn main() {}
@@ -0,0 +1,11 @@
error[E0277]: the trait bound `bool: IntoResponse` is not satisfied
--> tests/debug_handler/fail/wrong_return_type.rs:4:23
|
4 | async fn handler() -> bool {
| ^^^^ the trait `IntoResponse` is not implemented for `bool`
|
note: required by a bound in `__axum_macros_check_handler_into_response::{closure#0}::check`
--> tests/debug_handler/fail/wrong_return_type.rs:4:23
|
4 | async fn handler() -> bool {
| ^^^^ required by this bound in `__axum_macros_check_handler_into_response::{closure#0}::check`