mirror of
https://github.com/tokio-rs/axum.git
synced 2025-04-26 13:56:22 +02:00
fix some tests
This commit is contained in:
parent
e85538b047
commit
ae72d18e37
23 changed files with 24 additions and 55 deletions
axum-extra/src/extract/cookie
axum-macros
src
tests
axum/src
docs
extract
middleware
routing
|
@ -68,7 +68,7 @@ use std::{convert::Infallible, fmt, marker::PhantomData};
|
|||
/// .route("/set", post(set_secret))
|
||||
/// .route("/get", get(get_secret))
|
||||
/// .with_state(state);
|
||||
/// # let _: axum::routing::RouterService = app;
|
||||
/// # let _: axum::Router = app;
|
||||
/// ```
|
||||
pub struct PrivateCookieJar<K = Key> {
|
||||
jar: cookie::CookieJar,
|
||||
|
|
|
@ -86,7 +86,7 @@ use std::{convert::Infallible, fmt, marker::PhantomData};
|
|||
/// .route("/sessions", post(create_session))
|
||||
/// .route("/me", get(me))
|
||||
/// .with_state(state);
|
||||
/// # let _: axum::routing::RouterService = app;
|
||||
/// # let _: axum::Router = app;
|
||||
/// ```
|
||||
pub struct SignedCookieJar<K = Key> {
|
||||
jar: cookie::CookieJar,
|
||||
|
|
|
@ -610,7 +610,7 @@ pub fn derive_typed_path(input: TokenStream) -> TokenStream {
|
|||
/// let app = Router::new()
|
||||
/// .route("/", get(handler).post(other_handler))
|
||||
/// .with_state(state);
|
||||
/// # let _: axum::routing::RouterService = app;
|
||||
/// # let _: axum::Router = app;
|
||||
/// ```
|
||||
///
|
||||
/// [`FromRef`]: https://docs.rs/axum/latest/axum/extract/trait.FromRef.html
|
||||
|
|
|
@ -14,7 +14,7 @@ fn main() {
|
|||
auth_token: Default::default(),
|
||||
};
|
||||
|
||||
let _: axum::routing::RouterService = Router::new()
|
||||
let _: axum::Router = Router::new()
|
||||
.route("/", get(handler))
|
||||
.with_state(state);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use axum::{
|
|||
use axum_macros::FromRequest;
|
||||
|
||||
fn main() {
|
||||
let _: axum::routing::RouterService = Router::new()
|
||||
let _: axum::Router = Router::new()
|
||||
.route("/a", get(|_: AppState| async {}))
|
||||
.route("/b", get(|_: InnerState| async {}))
|
||||
.with_state(AppState::default());
|
||||
|
|
|
@ -6,7 +6,7 @@ use axum::{
|
|||
use axum_macros::FromRequestParts;
|
||||
|
||||
fn main() {
|
||||
let _: axum::routing::RouterService = Router::new()
|
||||
let _: axum::Router = Router::new()
|
||||
.route("/a", get(|_: AppState| async {}))
|
||||
.route("/b", get(|_: InnerState| async {}))
|
||||
.route("/c", get(|_: AppState, _: InnerState| async {}))
|
||||
|
|
|
@ -6,7 +6,7 @@ use axum::{
|
|||
};
|
||||
|
||||
fn main() {
|
||||
let _: axum::routing::RouterService = Router::new()
|
||||
let _: axum::Router = Router::new()
|
||||
.route("/b", get(|_: Extractor| async {}))
|
||||
.with_state(AppState::default());
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use axum::{
|
|||
use std::collections::HashMap;
|
||||
|
||||
fn main() {
|
||||
let _: axum::routing::RouterService = Router::new()
|
||||
let _: axum::Router = Router::new()
|
||||
.route("/b", get(|_: Extractor| async {}))
|
||||
.with_state(AppState::default());
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use axum::{
|
|||
use axum_macros::FromRequest;
|
||||
|
||||
fn main() {
|
||||
let _: axum::routing::RouterService = Router::new()
|
||||
let _: axum::Router = Router::new()
|
||||
.route("/", get(|_: Extractor| async {}))
|
||||
.with_state(AppState::default());
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use axum::{
|
|||
use axum_macros::FromRequest;
|
||||
|
||||
fn main() {
|
||||
let _: axum::routing::RouterService = Router::new()
|
||||
let _: axum::Router = Router::new()
|
||||
.route("/", get(|_: Extractor| async {}))
|
||||
.with_state(AppState::default());
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use axum::{
|
|||
use axum_macros::FromRequest;
|
||||
|
||||
fn main() {
|
||||
let _: axum::routing::RouterService = Router::new()
|
||||
let _: axum::Router = Router::new()
|
||||
.route("/b", get(|_: (), _: AppState| async {}))
|
||||
.route("/c", get(|_: (), _: InnerState| async {}))
|
||||
.with_state(AppState::default());
|
||||
|
|
|
@ -6,7 +6,7 @@ use axum::{
|
|||
use axum_macros::FromRequest;
|
||||
|
||||
fn main() {
|
||||
let _: axum::routing::RouterService = Router::new()
|
||||
let _: axum::Router = Router::new()
|
||||
.route("/b", get(|_: AppState| async {}))
|
||||
.with_state(AppState::default());
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use axum::{
|
|||
use axum_macros::FromRequestParts;
|
||||
|
||||
fn main() {
|
||||
let _: axum::routing::RouterService = Router::new()
|
||||
let _: axum::Router = Router::new()
|
||||
.route("/a", get(|_: AppState, _: InnerState, _: String| async {}))
|
||||
.route("/b", get(|_: AppState, _: String| async {}))
|
||||
.route("/c", get(|_: InnerState, _: String| async {}))
|
||||
|
|
|
@ -8,7 +8,7 @@ use axum::{
|
|||
use axum_macros::FromRequest;
|
||||
|
||||
fn main() {
|
||||
let _: axum::routing::RouterService = Router::new()
|
||||
let _: axum::Router = Router::new()
|
||||
.route("/a", get(|_: Extractor| async {}))
|
||||
.with_state(AppState::default());
|
||||
}
|
||||
|
|
|
@ -466,7 +466,7 @@ let app = Router::new()
|
|||
.route("/", get(handler))
|
||||
.layer(MyLayer { state: state.clone() })
|
||||
.with_state(state);
|
||||
# let _: axum::routing::RouterService = app;
|
||||
# let _: axum::Router = app;
|
||||
```
|
||||
|
||||
# Passing state from middleware to handlers
|
||||
|
@ -556,7 +556,7 @@ async fn rewrite_request_uri<B>(req: Request<B>, next: Next<B>) -> Response {
|
|||
// this can be any `tower::Layer`
|
||||
let middleware = axum::middleware::from_fn(rewrite_request_uri);
|
||||
|
||||
let app = Router::new().into_service();
|
||||
let app = Router::new();
|
||||
|
||||
// apply the layer around the whole `Router`
|
||||
// this way the middleware will run before `Router` receives the request
|
||||
|
|
|
@ -2,10 +2,6 @@ Convert this router into a [`MakeService`], that will store `C`'s
|
|||
associated `ConnectInfo` in a request extension such that [`ConnectInfo`]
|
||||
can extract it.
|
||||
|
||||
This is a convenience method for routers that don't have any state (i.e. the
|
||||
state type is `()`). Use [`RouterService::into_make_service_with_connect_info`]
|
||||
otherwise.
|
||||
|
||||
This enables extracting things like the client's remote address.
|
||||
|
||||
Extracting [`std::net::SocketAddr`] is supported out of the box:
|
||||
|
|
|
@ -178,7 +178,7 @@ let app = Router::new()
|
|||
.route("/", get(outer_handler))
|
||||
.nest_service("/foo", inner_router)
|
||||
.with_state(OuterState {});
|
||||
# let _: axum::routing::RouterService = app;
|
||||
# let _: axum::Router = app;
|
||||
```
|
||||
|
||||
Note that the inner router will still inherit the fallback from the outer
|
||||
|
|
|
@ -69,7 +69,7 @@ use axum::{routing::get, Router};
|
|||
|
||||
let app = Router::new().route_service(
|
||||
"/",
|
||||
Router::new().route("/foo", get(|| async {})).into_service(),
|
||||
Router::new().route("/foo", get(|| async {})),
|
||||
);
|
||||
# async {
|
||||
# axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
|
||||
|
|
|
@ -43,7 +43,7 @@ use std::{
|
|||
/// ) {
|
||||
/// // use `state`...
|
||||
/// }
|
||||
/// # let _: axum::routing::RouterService = app;
|
||||
/// # let _: axum::Router = app;
|
||||
/// ```
|
||||
///
|
||||
/// # With `MethodRouter`
|
||||
|
@ -138,7 +138,7 @@ use std::{
|
|||
/// State(state): State<AppState>,
|
||||
/// ) {
|
||||
/// }
|
||||
/// # let _: axum::routing::RouterService = app;
|
||||
/// # let _: axum::Router = app;
|
||||
/// ```
|
||||
///
|
||||
/// For convenience `FromRef` can also be derived using `#[derive(FromRef)]`.
|
||||
|
|
|
@ -137,7 +137,7 @@ pub fn from_fn<F, T>(f: F) -> FromFnLayer<F, (), T> {
|
|||
/// .route("/", get(|| async { /* ... */ }))
|
||||
/// .route_layer(middleware::from_fn_with_state(state.clone(), my_middleware))
|
||||
/// .with_state(state);
|
||||
/// # let _: axum::routing::RouterService = app;
|
||||
/// # let _: axum::Router = app;
|
||||
/// ```
|
||||
pub fn from_fn_with_state<F, S, T>(state: S, f: F) -> FromFnLayer<F, S, T> {
|
||||
FromFnLayer {
|
||||
|
|
|
@ -152,7 +152,7 @@ pub fn map_request<F, T>(f: F) -> MapRequestLayer<F, (), T> {
|
|||
/// .route("/", get(|| async { /* ... */ }))
|
||||
/// .route_layer(map_request_with_state(state.clone(), my_middleware))
|
||||
/// .with_state(state);
|
||||
/// # let _: axum::routing::RouterService = app;
|
||||
/// # let _: axum::Router = app;
|
||||
/// ```
|
||||
pub fn map_request_with_state<F, S, T>(state: S, f: F) -> MapRequestLayer<F, S, T> {
|
||||
MapRequestLayer {
|
||||
|
|
|
@ -136,7 +136,7 @@ pub fn map_response<F, T>(f: F) -> MapResponseLayer<F, (), T> {
|
|||
/// .route("/", get(|| async { /* ... */ }))
|
||||
/// .route_layer(map_response_with_state(state.clone(), my_middleware))
|
||||
/// .with_state(state);
|
||||
/// # let _: axum::routing::RouterService = app;
|
||||
/// # let _: axum::Router = app;
|
||||
/// ```
|
||||
pub fn map_response_with_state<F, S, T>(state: S, f: F) -> MapResponseLayer<F, S, T> {
|
||||
MapResponseLayer {
|
||||
|
|
|
@ -536,9 +536,6 @@ where
|
|||
/// # };
|
||||
/// ```
|
||||
///
|
||||
/// This is a convenience method for routers that don't have any state (i.e. the state type is
|
||||
/// `()`). Use [`RouterService::into_make_service`] otherwise.
|
||||
///
|
||||
/// [`MakeService`]: tower::make::MakeService
|
||||
pub fn into_make_service(self) -> IntoMakeService<Self> {
|
||||
// call `Router::with_state` such that everything is turned into `Route` eagerly
|
||||
|
@ -679,31 +676,7 @@ impl<S, B, E> fmt::Debug for Fallback<S, B, E> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Like `Fallback` but without the `S` param so it can be stored in `RouterService`
|
||||
pub(crate) enum FallbackRoute<B, E = Infallible> {
|
||||
Default(Route<B, E>),
|
||||
Service(Route<B, E>),
|
||||
}
|
||||
|
||||
impl<B, E> fmt::Debug for FallbackRoute<B, E> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Default(inner) => f.debug_tuple("Default").field(inner).finish(),
|
||||
Self::Service(inner) => f.debug_tuple("Service").field(inner).finish(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, E> Clone for FallbackRoute<B, E> {
|
||||
fn clone(&self) -> Self {
|
||||
match self {
|
||||
Self::Default(inner) => Self::Default(inner.clone()),
|
||||
Self::Service(inner) => Self::Service(inner.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::large_enum_variant)] // This type is only used at init time, probably fine
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
enum Endpoint<S, B> {
|
||||
MethodRouter(MethodRouter<S, B>),
|
||||
Route(Route<B>),
|
||||
|
|
Loading…
Add table
Reference in a new issue