mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-08 00:00:24 +02:00
Further compile time improvements (#220)
This improves compiles further when using lots of nested routes. Such as the example posted [here](https://github.com/tokio-rs/axum/issues/200#issuecomment-902541073). It seems rustc is really slow at checking bounds on these kinds of intermediate builder methods. Should probably file an issue about that.
This commit is contained in:
+2
-8
@@ -119,10 +119,7 @@ impl<S> Router<S> {
|
|||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if `description` doesn't start with `/`.
|
/// Panics if `description` doesn't start with `/`.
|
||||||
pub fn route<T, B>(self, description: &str, svc: T) -> Router<Route<T, S>>
|
pub fn route<T>(self, description: &str, svc: T) -> Router<Route<T, S>> {
|
||||||
where
|
|
||||||
T: Service<Request<B>> + Clone,
|
|
||||||
{
|
|
||||||
self.map(|fallback| Route {
|
self.map(|fallback| Route {
|
||||||
pattern: PathPattern::new(description),
|
pattern: PathPattern::new(description),
|
||||||
svc,
|
svc,
|
||||||
@@ -207,10 +204,7 @@ impl<S> Router<S> {
|
|||||||
/// If necessary you can use [`Router::boxed`] to box a group of routes
|
/// If necessary you can use [`Router::boxed`] to box a group of routes
|
||||||
/// making the type easier to name. This is sometimes useful when working with
|
/// making the type easier to name. This is sometimes useful when working with
|
||||||
/// `nest`.
|
/// `nest`.
|
||||||
pub fn nest<T, B>(self, description: &str, svc: T) -> Router<Nested<T, S>>
|
pub fn nest<T>(self, description: &str, svc: T) -> Router<Nested<T, S>> {
|
||||||
where
|
|
||||||
T: Service<Request<B>> + Clone,
|
|
||||||
{
|
|
||||||
self.map(|fallback| Nested {
|
self.map(|fallback| Nested {
|
||||||
pattern: PathPattern::new(description),
|
pattern: PathPattern::new(description),
|
||||||
svc,
|
svc,
|
||||||
|
|||||||
+13
-11
@@ -132,24 +132,26 @@ async fn handler_multiple_methods_last() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn service_propagates_errors() {
|
fn service_propagates_errors() {
|
||||||
let app = Router::new().route::<_, Body>("/echo", service::post(Svc));
|
let app = Router::new().route("/echo", service::post::<_, Body>(Svc));
|
||||||
|
|
||||||
check_make_svc::<_, _, _, hyper::Error>(app.into_make_service());
|
check_make_svc::<_, _, _, hyper::Error>(app.into_make_service());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn service_nested_propagates_errors() {
|
fn service_nested_propagates_errors() {
|
||||||
let app =
|
let app = Router::new().route(
|
||||||
Router::new().route::<_, Body>("/echo", Router::new().nest("/foo", service::post(Svc)));
|
"/echo",
|
||||||
|
Router::new().nest("/foo", service::post::<_, Body>(Svc)),
|
||||||
|
);
|
||||||
|
|
||||||
check_make_svc::<_, _, _, hyper::Error>(app.into_make_service());
|
check_make_svc::<_, _, _, hyper::Error>(app.into_make_service());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn service_handle_on_method() {
|
fn service_handle_on_method() {
|
||||||
let app = Router::new().route::<_, Body>(
|
let app = Router::new().route(
|
||||||
"/echo",
|
"/echo",
|
||||||
service::get(Svc).handle_error(handle_error::<hyper::Error>),
|
service::get::<_, Body>(Svc).handle_error(handle_error::<hyper::Error>),
|
||||||
);
|
);
|
||||||
|
|
||||||
check_make_svc::<_, _, _, Infallible>(app.into_make_service());
|
check_make_svc::<_, _, _, Infallible>(app.into_make_service());
|
||||||
@@ -157,9 +159,9 @@ fn service_handle_on_method() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn service_handle_on_method_multiple() {
|
fn service_handle_on_method_multiple() {
|
||||||
let app = Router::new().route::<_, Body>(
|
let app = Router::new().route(
|
||||||
"/echo",
|
"/echo",
|
||||||
service::get(Svc)
|
service::get::<_, Body>(Svc)
|
||||||
.post(Svc)
|
.post(Svc)
|
||||||
.handle_error(handle_error::<hyper::Error>),
|
.handle_error(handle_error::<hyper::Error>),
|
||||||
);
|
);
|
||||||
@@ -170,7 +172,7 @@ fn service_handle_on_method_multiple() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn service_handle_on_router() {
|
fn service_handle_on_router() {
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route::<_, Body>("/echo", service::get(Svc))
|
.route("/echo", service::get::<_, Body>(Svc))
|
||||||
.handle_error(handle_error::<hyper::Error>);
|
.handle_error(handle_error::<hyper::Error>);
|
||||||
|
|
||||||
check_make_svc::<_, _, _, Infallible>(app.into_make_service());
|
check_make_svc::<_, _, _, Infallible>(app.into_make_service());
|
||||||
@@ -179,7 +181,7 @@ fn service_handle_on_router() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn service_handle_on_router_still_impls_routing_dsl() {
|
fn service_handle_on_router_still_impls_routing_dsl() {
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route::<_, Body>("/echo", service::get(Svc))
|
.route("/echo", service::get::<_, Body>(Svc))
|
||||||
.handle_error(handle_error::<hyper::Error>)
|
.handle_error(handle_error::<hyper::Error>)
|
||||||
.route("/", get(unit));
|
.route("/", get(unit));
|
||||||
|
|
||||||
@@ -189,7 +191,7 @@ fn service_handle_on_router_still_impls_routing_dsl() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn layered() {
|
fn layered() {
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route::<_, Body>("/echo", get(unit))
|
.route("/echo", get::<_, Body, _>(unit))
|
||||||
.layer(timeout())
|
.layer(timeout())
|
||||||
.handle_error(handle_error::<BoxError>);
|
.handle_error(handle_error::<BoxError>);
|
||||||
|
|
||||||
@@ -199,7 +201,7 @@ fn layered() {
|
|||||||
#[tokio::test] // async because of `.boxed()`
|
#[tokio::test] // async because of `.boxed()`
|
||||||
async fn layered_boxed() {
|
async fn layered_boxed() {
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route::<_, Body>("/echo", get(unit))
|
.route("/echo", get::<_, Body, _>(unit))
|
||||||
.layer(timeout())
|
.layer(timeout())
|
||||||
.boxed()
|
.boxed()
|
||||||
.handle_error(handle_error::<BoxError>);
|
.handle_error(handle_error::<BoxError>);
|
||||||
|
|||||||
Reference in New Issue
Block a user