Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpdrsn committed Nov 23, 2022
1 parent 7dac86f commit 38c5961
Show file tree
Hide file tree
Showing 22 changed files with 23 additions and 54 deletions.
2 changes: 1 addition & 1 deletion axum-extra/src/extract/cookie/private.rs
Expand Up @@ -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;
/// ```
///
/// If you have been using `Arc<AppState>` you cannot implement `FromRef<Arc<AppState>> for Key`.
Expand Down
2 changes: 1 addition & 1 deletion axum-extra/src/extract/cookie/signed.rs
Expand Up @@ -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;
/// ```
/// If you have been using `Arc<AppState>` you cannot implement `FromRef<Arc<AppState>> for Key`.
/// You can use a new type instead:
Expand Down
2 changes: 1 addition & 1 deletion axum-macros/src/lib.rs
Expand Up @@ -606,7 +606,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
Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/from_ref/pass/basic.rs
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion axum-macros/tests/from_request/pass/state_enum_via.rs
Expand Up @@ -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());
Expand Down
Expand Up @@ -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 {}))
Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/from_request/pass/state_explicit.rs
Expand Up @@ -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());
}
Expand Down
Expand Up @@ -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());
}
Expand Down
Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/from_request/pass/state_field_infer.rs
Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/from_request/pass/state_via.rs
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/from_request/pass/state_via_infer.rs
Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/from_request/pass/state_via_parts.rs
Expand Up @@ -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 {}))
Expand Down
Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions axum/src/docs/middleware.md
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions axum/src/docs/routing/into_make_service_with_connect_info.md
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion axum/src/docs/routing/route_service.md
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions axum/src/extract/state.rs
Expand Up @@ -43,7 +43,7 @@ use std::{
/// ) {
/// // use `state`...
/// }
/// # let _: axum::routing::RouterService = app;
/// # let _: axum::Router = app;
/// ```
///
/// ## Combining stateful routers
Expand Down Expand Up @@ -209,7 +209,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)]`.
Expand Down
2 changes: 1 addition & 1 deletion axum/src/middleware/from_fn.rs
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion axum/src/middleware/map_request.rs
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion axum/src/middleware/map_response.rs
Expand Up @@ -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 {
Expand Down
29 changes: 1 addition & 28 deletions axum/src/routing/mod.rs
Expand Up @@ -571,9 +571,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
Expand Down Expand Up @@ -714,31 +711,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>),
Expand Down

0 comments on commit 38c5961

Please sign in to comment.