mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-24 00:00:16 +02:00
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:
co-authored by
Jonas Platte
parent
b1283e9708
commit
f6fc5ed80c
@@ -0,0 +1,10 @@
|
||||
use axum_macros::debug_handler;
|
||||
|
||||
struct A;
|
||||
|
||||
impl A {
|
||||
#[debug_handler]
|
||||
async fn handler() {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,10 @@
|
||||
use axum::{body::BoxBody, http::Request};
|
||||
use axum_macros::debug_handler;
|
||||
|
||||
#[debug_handler(body = BoxBody)]
|
||||
async fn handler(_: Request<BoxBody>) {}
|
||||
|
||||
#[debug_handler(body = axum::body::BoxBody,)]
|
||||
async fn handler_with_trailing_comma_and_type_path(_: Request<axum::body::BoxBody>) {}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,9 @@
|
||||
use axum_macros::debug_handler;
|
||||
use std::future::Future;
|
||||
|
||||
#[debug_handler]
|
||||
fn handler() -> impl Future<Output = ()> {
|
||||
async {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,9 @@
|
||||
use axum_macros::debug_handler;
|
||||
use axum::response::IntoResponse;
|
||||
|
||||
#[debug_handler]
|
||||
async fn handler() -> impl IntoResponse {
|
||||
"hi!"
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,6 @@
|
||||
use axum_macros::debug_handler;
|
||||
|
||||
#[debug_handler]
|
||||
async fn handler(_one: String, _two: String, _three: String) {}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,9 @@
|
||||
use axum_macros::debug_handler;
|
||||
|
||||
#[debug_handler]
|
||||
async fn handler(mut foo: String) -> String {
|
||||
foo += "bar";
|
||||
foo
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,9 @@
|
||||
use axum_macros::debug_handler;
|
||||
use std::future::{Ready, ready};
|
||||
|
||||
#[debug_handler]
|
||||
fn handler() -> Ready<()> {
|
||||
ready(())
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,132 @@
|
||||
use axum::{
|
||||
async_trait,
|
||||
extract::{FromRequest, RequestParts},
|
||||
response::IntoResponse,
|
||||
};
|
||||
use axum_macros::debug_handler;
|
||||
|
||||
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]
|
||||
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!()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum_macros::debug_handler;
|
||||
|
||||
struct A;
|
||||
|
||||
impl A {
|
||||
#[debug_handler]
|
||||
async fn handler() -> Self {
|
||||
A
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoResponse for A {
|
||||
fn into_response(self) -> Response {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -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() {}
|
||||
Reference in New Issue
Block a user