1
0
Fork 0
mirror of https://github.com/tokio-rs/axum.git synced 2025-07-30 01:13:13 +02:00

Re-format trybuild tests ()

This commit is contained in:
Jonas Platte 2024-11-26 19:04:01 +01:00 committed by GitHub
parent f1c79a459b
commit 9ddb25f089
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 97 additions and 154 deletions

View file

@ -1,5 +1,9 @@
use axum::{
body::Bytes,
http::{Method, Uri},
Json,
};
use axum_macros::debug_handler;
use axum::{Json, body::Bytes, http::{Method, Uri}};
#[debug_handler]
async fn one(_: Json<()>, _: String, _: Uri) {}

View file

@ -1,11 +1,11 @@
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.
--> tests/debug_handler/fail/multiple_request_consumers.rs:8:14
|
8 | async fn two(_: Json<()>, _: Method, _: Bytes, _: Uri, _: String) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
--> tests/debug_handler/fail/multiple_request_consumers.rs:12:14
|
12 | async fn two(_: Json<()>, _: Method, _: Bytes, _: Uri, _: String) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -1,8 +1,7 @@
use axum::response::AppendHeaders;
#[axum::debug_handler]
async fn handler(
) -> (
async fn handler() -> (
axum::http::StatusCode,
AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,

View file

@ -1,12 +1,12 @@
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 | ) -> (
| ___^
6 | | axum::http::StatusCode,
4 | async fn handler() -> (
| ____________________^
5 | | axum::http::StatusCode,
6 | | 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,
25 | | ) {
23 | | axum::http::StatusCode,
24 | | ) {
| |_^

View file

@ -1,10 +1,9 @@
#[axum::debug_handler]
async fn handler(
) -> (
async fn handler() -> (
axum::http::request::Parts, // this should be response parts, not request parts
axum::http::StatusCode,
) {
panic!()
}
fn main(){}
fn main() {}

View file

@ -1,7 +1,7 @@
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`

View file

@ -1,5 +1,5 @@
use axum_macros::debug_handler;
use axum::http::Uri;
use axum_macros::debug_handler;
#[debug_handler]
async fn handler(
@ -20,6 +20,7 @@ async fn handler(
_e15: Uri,
_e16: Uri,
_e17: Uri,
) {}
) {
}
fn main() {}

View file

@ -1,5 +1,5 @@
use axum::{http::Uri, Json};
use axum_macros::debug_handler;
use axum::{Json, http::Uri};
#[debug_handler]
async fn one(_: Json<()>, _: Uri) {}

View file

@ -4,16 +4,13 @@
async fn named_type() -> (
axum::http::StatusCode,
axum::Json<&'static str>,
axum::response::AppendHeaders<[( axum::http::HeaderName,&'static str); 1]>,
axum::response::AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
) {
panic!()
}
struct CustomIntoResponse{
}
impl axum::response::IntoResponse for CustomIntoResponse{
struct CustomIntoResponse {}
impl axum::response::IntoResponse for CustomIntoResponse {
fn into_response(self) -> axum::response::Response {
todo!()
}
@ -22,7 +19,7 @@ impl axum::response::IntoResponse for CustomIntoResponse{
async fn custom_type() -> (
axum::http::StatusCode,
CustomIntoResponse,
axum::response::AppendHeaders<[( axum::http::HeaderName,&'static str); 1]>,
axum::response::AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
) {
panic!()
}

View file

@ -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
--> 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`
|
= 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
--> 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`
|
= 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)
and $N others
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`

View file

@ -1,5 +1,5 @@
use axum_macros::debug_handler;
use axum::response::IntoResponse;
use axum_macros::debug_handler;
#[debug_handler]
async fn handler() -> impl IntoResponse {

View file

@ -1,5 +1,5 @@
use axum_macros::debug_handler;
use axum::extract::State;
use axum_macros::debug_handler;
#[debug_handler]
async fn handler(_: State<AppState>) {}
@ -8,22 +8,13 @@ async fn handler(_: State<AppState>) {}
async fn handler_2(_: axum::extract::State<AppState>) {}
#[debug_handler]
async fn handler_3(
_: axum::extract::State<AppState>,
_: axum::extract::State<AppState>,
) {}
async fn handler_3(_: axum::extract::State<AppState>, _: axum::extract::State<AppState>) {}
#[debug_handler]
async fn handler_4(
_: State<AppState>,
_: State<AppState>,
) {}
async fn handler_4(_: State<AppState>, _: State<AppState>) {}
#[debug_handler]
async fn handler_5(
_: axum::extract::State<AppState>,
_: State<AppState>,
) {}
async fn handler_5(_: axum::extract::State<AppState>, _: State<AppState>) {}
#[derive(Clone)]
struct AppState;

View file

@ -1,5 +1,5 @@
use axum_macros::debug_handler;
use axum::http::{Method, Uri};
use axum_macros::debug_handler;
#[debug_handler]
async fn handler(_one: Method, _two: Uri, _three: String) {}

View file

@ -1,5 +1,5 @@
use axum_macros::debug_handler;
use std::future::{Ready, ready};
use std::future::{ready, Ready};
#[debug_handler]
fn handler() -> Ready<()> {

View file

@ -1,5 +1,5 @@
use axum::{extract::Request, extract::State};
use axum_macros::debug_handler;
use axum::{extract::State, extract::Request};
#[debug_handler(state = AppState)]
async fn handler(_: State<AppState>, _: Request) {}

View file

@ -1,9 +1,4 @@
use axum::{
extract::Request,
response::Response,
middleware::Next,
debug_middleware,
};
use axum::{debug_middleware, extract::Request, middleware::Next, response::Response};
#[debug_middleware]
async fn my_middleware(next: Next, request: Request) -> Response {

View file

@ -1,5 +1,5 @@
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 {
| ^^^^^^^^^^

View file

@ -1,9 +1,4 @@
use axum::{
extract::Request,
response::Response,
middleware::Next,
debug_middleware,
};
use axum::{debug_middleware, extract::Request, middleware::Next, response::Response};
#[debug_middleware]
async fn my_middleware(request: Request, next: Next) -> Response {

View file

@ -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.
#[derive(Clone, FromRef)]
@ -14,7 +18,5 @@ fn main() {
auth_token: Default::default(),
};
let _: axum::Router = Router::new()
.route("/", get(handler))
.with_state(state);
let _: axum::Router = Router::new().route("/", get(handler)).with_state(state);
}

View file

@ -6,7 +6,7 @@ enum Extractor {
Foo {
#[from_request(via(axum::Extension))]
foo: (),
}
},
}
fn main() {}

View file

@ -1,5 +1,5 @@
use axum_macros::FromRequest;
use axum::extract::State;
use axum_macros::FromRequest;
#[derive(FromRequest)]
struct Extractor {

View file

@ -1,5 +1,5 @@
use axum::{
extract::{FromRequestParts, Extension},
extract::{Extension, FromRequestParts},
response::Response,
};

View file

@ -1,11 +1,8 @@
use axum::{
extract::FromRequest,
response::Response,
};
use axum::{extract::FromRequest, response::Response};
use axum_extra::{
TypedHeader,
typed_header::TypedHeaderRejection,
headers::{self, UserAgent},
typed_header::TypedHeaderRejection,
TypedHeader,
};
#[derive(FromRequest)]

View file

@ -1,11 +1,8 @@
use axum::{
extract::FromRequestParts,
response::Response,
};
use axum::{extract::FromRequestParts, response::Response};
use axum_extra::{
TypedHeader,
typed_header::TypedHeaderRejection,
headers::{self, UserAgent},
typed_header::TypedHeaderRejection,
TypedHeader,
};
#[derive(FromRequestParts)]

View file

@ -1,11 +1,11 @@
use axum::{
response::Response,
extract::{Extension, FromRequest},
response::Response,
};
use axum_extra::{
TypedHeader,
typed_header::TypedHeaderRejection,
headers::{self, UserAgent},
typed_header::TypedHeaderRejection,
TypedHeader,
};
#[derive(FromRequest)]

View file

@ -1,11 +1,11 @@
use axum::{
response::Response,
extract::{Extension, FromRequestParts},
response::Response,
};
use axum_extra::{
TypedHeader,
typed_header::TypedHeaderRejection,
headers::{self, UserAgent},
typed_header::TypedHeaderRejection,
TypedHeader,
};
#[derive(FromRequestParts)]

View file

@ -5,8 +5,8 @@ use axum::{
Router,
};
use axum_macros::FromRequest;
use std::collections::HashMap;
use serde::Deserialize;
use std::collections::HashMap;
fn main() {
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>) {}
#[derive(FromRequest, Deserialize)]
#[from_request(
via(axum::extract::Json),
rejection(MyJsonRejection),
)]
#[from_request(via(axum::extract::Json), rejection(MyJsonRejection))]
#[serde(transparent)]
struct MyJson(HashMap<String, String>);

View file

@ -5,8 +5,8 @@ use axum::{
Router,
};
use axum_macros::FromRequestParts;
use std::collections::HashMap;
use serde::Deserialize;
use std::collections::HashMap;
fn main() {
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>) {}
#[derive(FromRequestParts, Deserialize)]
#[from_request(
via(axum::extract::Query),
rejection(MyQueryRejection),
)]
#[from_request(via(axum::extract::Query), rejection(MyQueryRejection))]
#[serde(transparent)]
struct MyQuery(HashMap<String, String>);

View file

@ -19,10 +19,7 @@ async fn handler(_: MyJson<Payload>) {}
async fn handler_result(_: Result<MyJson<Payload>, MyJsonRejection>) {}
#[derive(FromRequest)]
#[from_request(
via(axum::Json),
rejection(MyJsonRejection),
)]
#[from_request(via(axum::Json), rejection(MyJsonRejection))]
struct MyJson<T>(T);
struct MyJsonRejection {}

View file

@ -19,10 +19,7 @@ async fn handler(_: MyQuery<Payload>) {}
async fn handler_result(_: Result<MyQuery<Payload>, MyQueryRejection>) {}
#[derive(FromRequestParts)]
#[from_request(
via(axum::extract::Query),
rejection(MyQueryRejection),
)]
#[from_request(via(axum::extract::Query), rejection(MyQueryRejection))]
struct MyQuery<T>(T);
struct MyQueryRejection {}

View file

@ -1,6 +1,6 @@
use axum_macros::FromRequest;
use axum::extract::FromRef;
use axum_extra::extract::cookie::{PrivateCookieJar, Key};
use axum_extra::extract::cookie::{Key, PrivateCookieJar};
use axum_macros::FromRequest;
#[derive(FromRequest)]
#[from_request(state(AppState))]

View file

@ -1,9 +1,9 @@
use axum_macros::FromRequest;
use axum::{
extract::{FromRef, State},
Router,
routing::get,
Router,
};
use axum_macros::FromRequest;
fn main() {
let _: axum::Router = Router::new()

View file

@ -1,9 +1,9 @@
use axum_macros::FromRequestParts;
use axum::{
extract::{FromRef, State, Query},
Router,
extract::{FromRef, Query, State},
routing::get,
Router,
};
use axum_macros::FromRequestParts;
use std::collections::HashMap;
fn main() {

View file

@ -1,5 +1,5 @@
use axum::{
extract::{State, FromRef},
extract::{FromRef, State},
routing::get,
Router,
};

View file

@ -1,8 +1,4 @@
use axum::{
extract::State,
routing::get,
Router,
};
use axum::{extract::State, routing::get, Router};
use axum_macros::FromRequest;
fn main() {

View file

@ -1,5 +1,5 @@
use axum_macros::FromRequest;
use axum::extract::State;
use axum_macros::FromRequest;
#[derive(FromRequest)]
struct Extractor {

View file

@ -1,5 +1,5 @@
use axum_macros::FromRequest;
use axum::extract::State;
use axum_macros::FromRequest;
#[derive(FromRequest)]
struct Extractor {

View file

@ -1,5 +1,5 @@
use axum_macros::FromRequestParts;
use axum::extract::State;
use axum_macros::FromRequestParts;
#[derive(FromRequestParts)]
struct Extractor {

View file

@ -1,8 +1,4 @@
use axum::{
extract::State,
routing::get,
Router,
};
use axum::{extract::State, routing::get, Router};
use axum_macros::FromRequest;
fn main() {

View file

@ -1,4 +1,3 @@
use std::convert::Infallible;
use axum::{
extract::State,
response::{IntoResponse, Response},
@ -6,6 +5,7 @@ use axum::{
Router,
};
use axum_macros::FromRequest;
use std::convert::Infallible;
fn main() {
let _: axum::Router = Router::new()

View file

@ -3,10 +3,7 @@ use axum_macros::FromRequest;
use serde::Deserialize;
#[derive(FromRequest)]
struct Extractor(
Query<Payload>,
axum::extract::Json<Payload>,
);
struct Extractor(Query<Payload>, axum::extract::Json<Payload>);
#[derive(Deserialize)]
struct Payload {}

View file

@ -3,10 +3,7 @@ use axum_macros::FromRequestParts;
use serde::Deserialize;
#[derive(FromRequestParts)]
struct Extractor(
Query<Payload>,
axum::extract::Path<Payload>,
);
struct Extractor(Query<Payload>, axum::extract::Path<Payload>);
#[derive(Deserialize)]
struct Payload {}

View file

@ -5,5 +5,4 @@ use serde::Deserialize;
#[typed_path("/users/{id}")]
struct MyPath {}
fn main() {
}
fn main() {}

View file

@ -1,5 +1,5 @@
use axum_extra::routing::TypedPath;
use axum::http::Uri;
use axum_extra::routing::TypedPath;
use serde::Deserialize;
#[derive(TypedPath, Deserialize)]

View file

@ -1,5 +1,5 @@
use axum_extra::routing::{TypedPath, RouterExt};
use axum::{extract::rejection::PathRejection, http::StatusCode};
use axum_extra::routing::{RouterExt, TypedPath};
use serde::Deserialize;
#[derive(TypedPath, Deserialize)]

View file

@ -5,8 +5,7 @@ use axum_extra::routing::TypedPath;
struct MyPath;
fn main() {
_ = axum::Router::<()>::new()
.route("/", axum::routing::get(|_: MyPath| async {}));
_ = axum::Router::<()>::new().route("/", axum::routing::get(|_: MyPath| async {}));
assert_eq!(MyPath::PATH, "/users");
assert_eq!(format!("{}", MyPath), "/users");

View file

@ -22,11 +22,5 @@ fn main() {
"/a%20b"
);
assert_eq!(
format!(
"{}",
Unnamed("a b".to_string()),
),
"/a%20b"
);
assert_eq!(format!("{}", Unnamed("a b".to_string()),), "/a%20b");
}