mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-29 00:00:18 +02:00
Re-format trybuild tests (#3049)
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
|
use axum::{
|
||||||
|
body::Bytes,
|
||||||
|
http::{Method, Uri},
|
||||||
|
Json,
|
||||||
|
};
|
||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
use axum::{Json, body::Bytes, http::{Method, Uri}};
|
|
||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
async fn one(_: Json<()>, _: String, _: Uri) {}
|
async fn one(_: Json<()>, _: String, _: Uri) {}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
error: Can't have two extractors that consume the request body. `Json<_>` and `String` both do that.
|
error: Can't have two extractors that consume the request body. `Json<_>` and `String` both do that.
|
||||||
--> tests/debug_handler/fail/multiple_request_consumers.rs:5:14
|
--> tests/debug_handler/fail/multiple_request_consumers.rs:9:14
|
||||||
|
|
|
|
||||||
5 | async fn one(_: Json<()>, _: String, _: Uri) {}
|
9 | async fn one(_: Json<()>, _: String, _: Uri) {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: Can't have more than one extractor that consume the request body. `Json<_>`, `Bytes`, and `String` all do that.
|
error: Can't have more than one extractor that consume the request body. `Json<_>`, `Bytes`, and `String` all do that.
|
||||||
--> tests/debug_handler/fail/multiple_request_consumers.rs:8:14
|
--> tests/debug_handler/fail/multiple_request_consumers.rs:12:14
|
||||||
|
|
|
|
||||||
8 | async fn two(_: Json<()>, _: Method, _: Bytes, _: Uri, _: String) {}
|
12 | async fn two(_: Json<()>, _: Method, _: Bytes, _: Uri, _: String) {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
use axum::response::AppendHeaders;
|
use axum::response::AppendHeaders;
|
||||||
|
|
||||||
#[axum::debug_handler]
|
#[axum::debug_handler]
|
||||||
async fn handler(
|
async fn handler() -> (
|
||||||
) -> (
|
|
||||||
axum::http::StatusCode,
|
axum::http::StatusCode,
|
||||||
AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
|
AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
|
||||||
AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
|
AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
error: Cannot return tuples with more than 17 elements
|
error: Cannot return tuples with more than 17 elements
|
||||||
--> tests/debug_handler/fail/output_tuple_too_many.rs:5:3
|
--> tests/debug_handler/fail/output_tuple_too_many.rs:4:20
|
||||||
|
|
|
|
||||||
5 | ) -> (
|
4 | async fn handler() -> (
|
||||||
| ___^
|
| ____________________^
|
||||||
6 | | axum::http::StatusCode,
|
5 | | axum::http::StatusCode,
|
||||||
|
6 | | AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
|
||||||
7 | | AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
|
7 | | AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
|
||||||
8 | | AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
|
|
||||||
... |
|
... |
|
||||||
24 | | axum::http::StatusCode,
|
23 | | axum::http::StatusCode,
|
||||||
25 | | ) {
|
24 | | ) {
|
||||||
| |_^
|
| |_^
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
#[axum::debug_handler]
|
#[axum::debug_handler]
|
||||||
async fn handler(
|
async fn handler() -> (
|
||||||
) -> (
|
|
||||||
axum::http::request::Parts, // this should be response parts, not request parts
|
axum::http::request::Parts, // this should be response parts, not request parts
|
||||||
axum::http::StatusCode,
|
axum::http::StatusCode,
|
||||||
) {
|
) {
|
||||||
panic!()
|
panic!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(){}
|
fn main() {}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> tests/debug_handler/fail/returning_request_parts.rs:4:5
|
--> tests/debug_handler/fail/returning_request_parts.rs:3:5
|
||||||
|
|
|
|
||||||
4 | axum::http::request::Parts, // this should be response parts, not request parts
|
3 | axum::http::request::Parts, // this should be response parts, not request parts
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
| |
|
| |
|
||||||
| expected `axum::http::response::Parts`, found `axum::http::request::Parts`
|
| expected `axum::http::response::Parts`, found `axum::http::request::Parts`
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use axum_macros::debug_handler;
|
|
||||||
use axum::http::Uri;
|
use axum::http::Uri;
|
||||||
|
use axum_macros::debug_handler;
|
||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
async fn handler(
|
async fn handler(
|
||||||
@@ -20,6 +20,7 @@ async fn handler(
|
|||||||
_e15: Uri,
|
_e15: Uri,
|
||||||
_e16: Uri,
|
_e16: Uri,
|
||||||
_e17: Uri,
|
_e17: Uri,
|
||||||
) {}
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
use axum::{http::Uri, Json};
|
||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
use axum::{Json, http::Uri};
|
|
||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
async fn one(_: Json<()>, _: Uri) {}
|
async fn one(_: Json<()>, _: Uri) {}
|
||||||
|
|||||||
@@ -4,16 +4,13 @@
|
|||||||
async fn named_type() -> (
|
async fn named_type() -> (
|
||||||
axum::http::StatusCode,
|
axum::http::StatusCode,
|
||||||
axum::Json<&'static str>,
|
axum::Json<&'static str>,
|
||||||
axum::response::AppendHeaders<[( axum::http::HeaderName,&'static str); 1]>,
|
axum::response::AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
|
||||||
) {
|
) {
|
||||||
panic!()
|
panic!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct CustomIntoResponse {}
|
||||||
struct CustomIntoResponse{
|
impl axum::response::IntoResponse for CustomIntoResponse {
|
||||||
|
|
||||||
}
|
|
||||||
impl axum::response::IntoResponse for CustomIntoResponse{
|
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
@@ -22,7 +19,7 @@ impl axum::response::IntoResponse for CustomIntoResponse{
|
|||||||
async fn custom_type() -> (
|
async fn custom_type() -> (
|
||||||
axum::http::StatusCode,
|
axum::http::StatusCode,
|
||||||
CustomIntoResponse,
|
CustomIntoResponse,
|
||||||
axum::response::AppendHeaders<[( axum::http::HeaderName,&'static str); 1]>,
|
axum::response::AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
|
||||||
) {
|
) {
|
||||||
panic!()
|
panic!()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ error: `Json<_>` must be the last element in a response tuple
|
|||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0277]: the trait bound `CustomIntoResponse: IntoResponseParts` is not satisfied
|
error[E0277]: the trait bound `CustomIntoResponse: IntoResponseParts` is not satisfied
|
||||||
--> tests/debug_handler/fail/wrong_return_tuple.rs:24:5
|
--> tests/debug_handler/fail/wrong_return_tuple.rs:21:5
|
||||||
|
|
|
|
||||||
24 | CustomIntoResponse,
|
21 | CustomIntoResponse,
|
||||||
| ^^^^^^^^^^^^^^^^^^ the trait `IntoResponseParts` is not implemented for `CustomIntoResponse`
|
| ^^^^^^^^^^^^^^^^^^ the trait `IntoResponseParts` is not implemented for `CustomIntoResponse`
|
||||||
|
|
|
|
||||||
= help: the following other types implement trait `IntoResponseParts`:
|
= help: the following other types implement trait `IntoResponseParts`:
|
||||||
@@ -27,9 +27,9 @@ help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
|
|||||||
|
|
|
|
||||||
|
|
||||||
error[E0277]: the trait bound `CustomIntoResponse: IntoResponseParts` is not satisfied
|
error[E0277]: the trait bound `CustomIntoResponse: IntoResponseParts` is not satisfied
|
||||||
--> tests/debug_handler/fail/wrong_return_tuple.rs:24:5
|
--> tests/debug_handler/fail/wrong_return_tuple.rs:21:5
|
||||||
|
|
|
|
||||||
24 | CustomIntoResponse,
|
21 | CustomIntoResponse,
|
||||||
| ^^^^^^^^^^^^^^^^^^ the trait `IntoResponseParts` is not implemented for `CustomIntoResponse`
|
| ^^^^^^^^^^^^^^^^^^ the trait `IntoResponseParts` is not implemented for `CustomIntoResponse`
|
||||||
|
|
|
|
||||||
= help: the following other types implement trait `IntoResponseParts`:
|
= help: the following other types implement trait `IntoResponseParts`:
|
||||||
@@ -43,7 +43,7 @@ error[E0277]: the trait bound `CustomIntoResponse: IntoResponseParts` is not sat
|
|||||||
(T1, T2, T3, T4, T5, T6, T7, T8)
|
(T1, T2, T3, T4, T5, T6, T7, T8)
|
||||||
and $N others
|
and $N others
|
||||||
note: required by a bound in `__axum_macros_check_custom_type_into_response_parts_1_check`
|
note: required by a bound in `__axum_macros_check_custom_type_into_response_parts_1_check`
|
||||||
--> tests/debug_handler/fail/wrong_return_tuple.rs:24:5
|
--> tests/debug_handler/fail/wrong_return_tuple.rs:21:5
|
||||||
|
|
|
|
||||||
24 | CustomIntoResponse,
|
21 | CustomIntoResponse,
|
||||||
| ^^^^^^^^^^^^^^^^^^ required by this bound in `__axum_macros_check_custom_type_into_response_parts_1_check`
|
| ^^^^^^^^^^^^^^^^^^ required by this bound in `__axum_macros_check_custom_type_into_response_parts_1_check`
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use axum_macros::debug_handler;
|
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
|
use axum_macros::debug_handler;
|
||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
async fn handler() -> impl IntoResponse {
|
async fn handler() -> impl IntoResponse {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use axum_macros::debug_handler;
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
|
use axum_macros::debug_handler;
|
||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
async fn handler(_: State<AppState>) {}
|
async fn handler(_: State<AppState>) {}
|
||||||
@@ -8,22 +8,13 @@ async fn handler(_: State<AppState>) {}
|
|||||||
async fn handler_2(_: axum::extract::State<AppState>) {}
|
async fn handler_2(_: axum::extract::State<AppState>) {}
|
||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
async fn handler_3(
|
async fn handler_3(_: axum::extract::State<AppState>, _: axum::extract::State<AppState>) {}
|
||||||
_: axum::extract::State<AppState>,
|
|
||||||
_: axum::extract::State<AppState>,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
async fn handler_4(
|
async fn handler_4(_: State<AppState>, _: State<AppState>) {}
|
||||||
_: State<AppState>,
|
|
||||||
_: State<AppState>,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
async fn handler_5(
|
async fn handler_5(_: axum::extract::State<AppState>, _: State<AppState>) {}
|
||||||
_: axum::extract::State<AppState>,
|
|
||||||
_: State<AppState>,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct AppState;
|
struct AppState;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use axum_macros::debug_handler;
|
|
||||||
use axum::http::{Method, Uri};
|
use axum::http::{Method, Uri};
|
||||||
|
use axum_macros::debug_handler;
|
||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
async fn handler(_one: Method, _two: Uri, _three: String) {}
|
async fn handler(_one: Method, _two: Uri, _three: String) {}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
use std::future::{Ready, ready};
|
use std::future::{ready, Ready};
|
||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
fn handler() -> Ready<()> {
|
fn handler() -> Ready<()> {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
use axum::{extract::Request, extract::State};
|
||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
use axum::{extract::State, extract::Request};
|
|
||||||
|
|
||||||
#[debug_handler(state = AppState)]
|
#[debug_handler(state = AppState)]
|
||||||
async fn handler(_: State<AppState>, _: Request) {}
|
async fn handler(_: State<AppState>, _: Request) {}
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
use axum::{
|
use axum::{debug_middleware, extract::Request, middleware::Next, response::Response};
|
||||||
extract::Request,
|
|
||||||
response::Response,
|
|
||||||
middleware::Next,
|
|
||||||
debug_middleware,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[debug_middleware]
|
#[debug_middleware]
|
||||||
async fn my_middleware(next: Next, request: Request) -> Response {
|
async fn my_middleware(next: Next, request: Request) -> Response {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
error: `axum::middleware::Next` must the last argument
|
error: `axum::middleware::Next` must the last argument
|
||||||
--> tests/debug_middleware/fail/next_not_last.rs:9:24
|
--> tests/debug_middleware/fail/next_not_last.rs:4:24
|
||||||
|
|
|
|
||||||
9 | async fn my_middleware(next: Next, request: Request) -> Response {
|
4 | async fn my_middleware(next: Next, request: Request) -> Response {
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
use axum::{
|
use axum::{debug_middleware, extract::Request, middleware::Next, response::Response};
|
||||||
extract::Request,
|
|
||||||
response::Response,
|
|
||||||
middleware::Next,
|
|
||||||
debug_middleware,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[debug_middleware]
|
#[debug_middleware]
|
||||||
async fn my_middleware(request: Request, next: Next) -> Response {
|
async fn my_middleware(request: Request, next: Next) -> Response {
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
use axum::{Router, routing::get, extract::{State, FromRef}};
|
use axum::{
|
||||||
|
extract::{FromRef, State},
|
||||||
|
routing::get,
|
||||||
|
Router,
|
||||||
|
};
|
||||||
|
|
||||||
// This will implement `FromRef` for each field in the struct.
|
// This will implement `FromRef` for each field in the struct.
|
||||||
#[derive(Clone, FromRef)]
|
#[derive(Clone, FromRef)]
|
||||||
@@ -14,7 +18,5 @@ fn main() {
|
|||||||
auth_token: Default::default(),
|
auth_token: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let _: axum::Router = Router::new()
|
let _: axum::Router = Router::new().route("/", get(handler)).with_state(state);
|
||||||
.route("/", get(handler))
|
|
||||||
.with_state(state);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ enum Extractor {
|
|||||||
Foo {
|
Foo {
|
||||||
#[from_request(via(axum::Extension))]
|
#[from_request(via(axum::Extension))]
|
||||||
foo: (),
|
foo: (),
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use axum_macros::FromRequest;
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
|
use axum_macros::FromRequest;
|
||||||
|
|
||||||
#[derive(FromRequest)]
|
#[derive(FromRequest)]
|
||||||
struct Extractor {
|
struct Extractor {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use axum::{
|
use axum::{
|
||||||
extract::{FromRequestParts, Extension},
|
extract::{Extension, FromRequestParts},
|
||||||
response::Response,
|
response::Response,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
use axum::{
|
use axum::{extract::FromRequest, response::Response};
|
||||||
extract::FromRequest,
|
|
||||||
response::Response,
|
|
||||||
};
|
|
||||||
use axum_extra::{
|
use axum_extra::{
|
||||||
TypedHeader,
|
|
||||||
typed_header::TypedHeaderRejection,
|
|
||||||
headers::{self, UserAgent},
|
headers::{self, UserAgent},
|
||||||
|
typed_header::TypedHeaderRejection,
|
||||||
|
TypedHeader,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(FromRequest)]
|
#[derive(FromRequest)]
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
use axum::{
|
use axum::{extract::FromRequestParts, response::Response};
|
||||||
extract::FromRequestParts,
|
|
||||||
response::Response,
|
|
||||||
};
|
|
||||||
use axum_extra::{
|
use axum_extra::{
|
||||||
TypedHeader,
|
|
||||||
typed_header::TypedHeaderRejection,
|
|
||||||
headers::{self, UserAgent},
|
headers::{self, UserAgent},
|
||||||
|
typed_header::TypedHeaderRejection,
|
||||||
|
TypedHeader,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(FromRequestParts)]
|
#[derive(FromRequestParts)]
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use axum::{
|
use axum::{
|
||||||
response::Response,
|
|
||||||
extract::{Extension, FromRequest},
|
extract::{Extension, FromRequest},
|
||||||
|
response::Response,
|
||||||
};
|
};
|
||||||
use axum_extra::{
|
use axum_extra::{
|
||||||
TypedHeader,
|
|
||||||
typed_header::TypedHeaderRejection,
|
|
||||||
headers::{self, UserAgent},
|
headers::{self, UserAgent},
|
||||||
|
typed_header::TypedHeaderRejection,
|
||||||
|
TypedHeader,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(FromRequest)]
|
#[derive(FromRequest)]
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use axum::{
|
use axum::{
|
||||||
response::Response,
|
|
||||||
extract::{Extension, FromRequestParts},
|
extract::{Extension, FromRequestParts},
|
||||||
|
response::Response,
|
||||||
};
|
};
|
||||||
use axum_extra::{
|
use axum_extra::{
|
||||||
TypedHeader,
|
|
||||||
typed_header::TypedHeaderRejection,
|
|
||||||
headers::{self, UserAgent},
|
headers::{self, UserAgent},
|
||||||
|
typed_header::TypedHeaderRejection,
|
||||||
|
TypedHeader,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(FromRequestParts)]
|
#[derive(FromRequestParts)]
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ use axum::{
|
|||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use axum_macros::FromRequest;
|
use axum_macros::FromRequest;
|
||||||
use std::collections::HashMap;
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _: Router = Router::new().route("/", get(handler).post(handler_result));
|
let _: Router = Router::new().route("/", get(handler).post(handler_result));
|
||||||
@@ -17,10 +17,7 @@ async fn handler(_: MyJson) {}
|
|||||||
async fn handler_result(_: Result<MyJson, MyJsonRejection>) {}
|
async fn handler_result(_: Result<MyJson, MyJsonRejection>) {}
|
||||||
|
|
||||||
#[derive(FromRequest, Deserialize)]
|
#[derive(FromRequest, Deserialize)]
|
||||||
#[from_request(
|
#[from_request(via(axum::extract::Json), rejection(MyJsonRejection))]
|
||||||
via(axum::extract::Json),
|
|
||||||
rejection(MyJsonRejection),
|
|
||||||
)]
|
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
struct MyJson(HashMap<String, String>);
|
struct MyJson(HashMap<String, String>);
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ use axum::{
|
|||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use axum_macros::FromRequestParts;
|
use axum_macros::FromRequestParts;
|
||||||
use std::collections::HashMap;
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _: Router = Router::new().route("/", get(handler).post(handler_result));
|
let _: Router = Router::new().route("/", get(handler).post(handler_result));
|
||||||
@@ -17,10 +17,7 @@ async fn handler(_: MyQuery) {}
|
|||||||
async fn handler_result(_: Result<MyQuery, MyQueryRejection>) {}
|
async fn handler_result(_: Result<MyQuery, MyQueryRejection>) {}
|
||||||
|
|
||||||
#[derive(FromRequestParts, Deserialize)]
|
#[derive(FromRequestParts, Deserialize)]
|
||||||
#[from_request(
|
#[from_request(via(axum::extract::Query), rejection(MyQueryRejection))]
|
||||||
via(axum::extract::Query),
|
|
||||||
rejection(MyQueryRejection),
|
|
||||||
)]
|
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
struct MyQuery(HashMap<String, String>);
|
struct MyQuery(HashMap<String, String>);
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,7 @@ async fn handler(_: MyJson<Payload>) {}
|
|||||||
async fn handler_result(_: Result<MyJson<Payload>, MyJsonRejection>) {}
|
async fn handler_result(_: Result<MyJson<Payload>, MyJsonRejection>) {}
|
||||||
|
|
||||||
#[derive(FromRequest)]
|
#[derive(FromRequest)]
|
||||||
#[from_request(
|
#[from_request(via(axum::Json), rejection(MyJsonRejection))]
|
||||||
via(axum::Json),
|
|
||||||
rejection(MyJsonRejection),
|
|
||||||
)]
|
|
||||||
struct MyJson<T>(T);
|
struct MyJson<T>(T);
|
||||||
|
|
||||||
struct MyJsonRejection {}
|
struct MyJsonRejection {}
|
||||||
|
|||||||
@@ -19,10 +19,7 @@ async fn handler(_: MyQuery<Payload>) {}
|
|||||||
async fn handler_result(_: Result<MyQuery<Payload>, MyQueryRejection>) {}
|
async fn handler_result(_: Result<MyQuery<Payload>, MyQueryRejection>) {}
|
||||||
|
|
||||||
#[derive(FromRequestParts)]
|
#[derive(FromRequestParts)]
|
||||||
#[from_request(
|
#[from_request(via(axum::extract::Query), rejection(MyQueryRejection))]
|
||||||
via(axum::extract::Query),
|
|
||||||
rejection(MyQueryRejection),
|
|
||||||
)]
|
|
||||||
struct MyQuery<T>(T);
|
struct MyQuery<T>(T);
|
||||||
|
|
||||||
struct MyQueryRejection {}
|
struct MyQueryRejection {}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use axum_macros::FromRequest;
|
|
||||||
use axum::extract::FromRef;
|
use axum::extract::FromRef;
|
||||||
use axum_extra::extract::cookie::{PrivateCookieJar, Key};
|
use axum_extra::extract::cookie::{Key, PrivateCookieJar};
|
||||||
|
use axum_macros::FromRequest;
|
||||||
|
|
||||||
#[derive(FromRequest)]
|
#[derive(FromRequest)]
|
||||||
#[from_request(state(AppState))]
|
#[from_request(state(AppState))]
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use axum_macros::FromRequest;
|
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{FromRef, State},
|
extract::{FromRef, State},
|
||||||
Router,
|
|
||||||
routing::get,
|
routing::get,
|
||||||
|
Router,
|
||||||
};
|
};
|
||||||
|
use axum_macros::FromRequest;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _: axum::Router = Router::new()
|
let _: axum::Router = Router::new()
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use axum_macros::FromRequestParts;
|
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{FromRef, State, Query},
|
extract::{FromRef, Query, State},
|
||||||
Router,
|
|
||||||
routing::get,
|
routing::get,
|
||||||
|
Router,
|
||||||
};
|
};
|
||||||
|
use axum_macros::FromRequestParts;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use axum::{
|
use axum::{
|
||||||
extract::{State, FromRef},
|
extract::{FromRef, State},
|
||||||
routing::get,
|
routing::get,
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
use axum::{
|
use axum::{extract::State, routing::get, Router};
|
||||||
extract::State,
|
|
||||||
routing::get,
|
|
||||||
Router,
|
|
||||||
};
|
|
||||||
use axum_macros::FromRequest;
|
use axum_macros::FromRequest;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use axum_macros::FromRequest;
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
|
use axum_macros::FromRequest;
|
||||||
|
|
||||||
#[derive(FromRequest)]
|
#[derive(FromRequest)]
|
||||||
struct Extractor {
|
struct Extractor {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use axum_macros::FromRequest;
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
|
use axum_macros::FromRequest;
|
||||||
|
|
||||||
#[derive(FromRequest)]
|
#[derive(FromRequest)]
|
||||||
struct Extractor {
|
struct Extractor {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use axum_macros::FromRequestParts;
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
|
use axum_macros::FromRequestParts;
|
||||||
|
|
||||||
#[derive(FromRequestParts)]
|
#[derive(FromRequestParts)]
|
||||||
struct Extractor {
|
struct Extractor {
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
use axum::{
|
use axum::{extract::State, routing::get, Router};
|
||||||
extract::State,
|
|
||||||
routing::get,
|
|
||||||
Router,
|
|
||||||
};
|
|
||||||
use axum_macros::FromRequest;
|
use axum_macros::FromRequest;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use std::convert::Infallible;
|
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::State,
|
extract::State,
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Response},
|
||||||
@@ -6,6 +5,7 @@ use axum::{
|
|||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use axum_macros::FromRequest;
|
use axum_macros::FromRequest;
|
||||||
|
use std::convert::Infallible;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _: axum::Router = Router::new()
|
let _: axum::Router = Router::new()
|
||||||
|
|||||||
@@ -3,10 +3,7 @@ use axum_macros::FromRequest;
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(FromRequest)]
|
#[derive(FromRequest)]
|
||||||
struct Extractor(
|
struct Extractor(Query<Payload>, axum::extract::Json<Payload>);
|
||||||
Query<Payload>,
|
|
||||||
axum::extract::Json<Payload>,
|
|
||||||
);
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Payload {}
|
struct Payload {}
|
||||||
|
|||||||
@@ -3,10 +3,7 @@ use axum_macros::FromRequestParts;
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(FromRequestParts)]
|
#[derive(FromRequestParts)]
|
||||||
struct Extractor(
|
struct Extractor(Query<Payload>, axum::extract::Path<Payload>);
|
||||||
Query<Payload>,
|
|
||||||
axum::extract::Path<Payload>,
|
|
||||||
);
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Payload {}
|
struct Payload {}
|
||||||
|
|||||||
@@ -5,5 +5,4 @@ use serde::Deserialize;
|
|||||||
#[typed_path("/users/{id}")]
|
#[typed_path("/users/{id}")]
|
||||||
struct MyPath {}
|
struct MyPath {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use axum_extra::routing::TypedPath;
|
|
||||||
use axum::http::Uri;
|
use axum::http::Uri;
|
||||||
|
use axum_extra::routing::TypedPath;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(TypedPath, Deserialize)]
|
#[derive(TypedPath, Deserialize)]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use axum_extra::routing::{TypedPath, RouterExt};
|
|
||||||
use axum::{extract::rejection::PathRejection, http::StatusCode};
|
use axum::{extract::rejection::PathRejection, http::StatusCode};
|
||||||
|
use axum_extra::routing::{RouterExt, TypedPath};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(TypedPath, Deserialize)]
|
#[derive(TypedPath, Deserialize)]
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ use axum_extra::routing::TypedPath;
|
|||||||
struct MyPath;
|
struct MyPath;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
_ = axum::Router::<()>::new()
|
_ = axum::Router::<()>::new().route("/", axum::routing::get(|_: MyPath| async {}));
|
||||||
.route("/", axum::routing::get(|_: MyPath| async {}));
|
|
||||||
|
|
||||||
assert_eq!(MyPath::PATH, "/users");
|
assert_eq!(MyPath::PATH, "/users");
|
||||||
assert_eq!(format!("{}", MyPath), "/users");
|
assert_eq!(format!("{}", MyPath), "/users");
|
||||||
|
|||||||
@@ -22,11 +22,5 @@ fn main() {
|
|||||||
"/a%20b"
|
"/a%20b"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(format!("{}", Unnamed("a b".to_string()),), "/a%20b");
|
||||||
format!(
|
|
||||||
"{}",
|
|
||||||
Unnamed("a b".to_string()),
|
|
||||||
),
|
|
||||||
"/a%20b"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user