Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further compile time improvements #220

Merged
merged 1 commit into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ impl<S> Router<S> {
/// # Panics
///
/// Panics if `description` doesn't start with `/`.
pub fn route<T, B>(self, description: &str, svc: T) -> Router<Route<T, S>>
where
T: Service<Request<B>> + Clone,
{
pub fn route<T>(self, description: &str, svc: T) -> Router<Route<T, S>> {
self.map(|fallback| Route {
pattern: PathPattern::new(description),
svc,
Expand Down Expand Up @@ -207,10 +204,7 @@ impl<S> Router<S> {
/// 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
/// `nest`.
pub fn nest<T, B>(self, description: &str, svc: T) -> Router<Nested<T, S>>
where
T: Service<Request<B>> + Clone,
{
pub fn nest<T>(self, description: &str, svc: T) -> Router<Nested<T, S>> {
self.map(|fallback| Nested {
pattern: PathPattern::new(description),
svc,
Expand Down
24 changes: 13 additions & 11 deletions src/tests/handle_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,34 +132,36 @@ async fn handler_multiple_methods_last() {

#[test]
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());
}

#[test]
fn service_nested_propagates_errors() {
let app =
Router::new().route::<_, Body>("/echo", Router::new().nest("/foo", service::post(Svc)));
let app = Router::new().route(
"/echo",
Router::new().nest("/foo", service::post::<_, Body>(Svc)),
);

check_make_svc::<_, _, _, hyper::Error>(app.into_make_service());
}

#[test]
fn service_handle_on_method() {
let app = Router::new().route::<_, Body>(
let app = Router::new().route(
"/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());
}

#[test]
fn service_handle_on_method_multiple() {
let app = Router::new().route::<_, Body>(
let app = Router::new().route(
"/echo",
service::get(Svc)
service::get::<_, Body>(Svc)
.post(Svc)
.handle_error(handle_error::<hyper::Error>),
);
Expand All @@ -170,7 +172,7 @@ fn service_handle_on_method_multiple() {
#[test]
fn service_handle_on_router() {
let app = Router::new()
.route::<_, Body>("/echo", service::get(Svc))
.route("/echo", service::get::<_, Body>(Svc))
.handle_error(handle_error::<hyper::Error>);

check_make_svc::<_, _, _, Infallible>(app.into_make_service());
Expand All @@ -179,7 +181,7 @@ fn service_handle_on_router() {
#[test]
fn service_handle_on_router_still_impls_routing_dsl() {
let app = Router::new()
.route::<_, Body>("/echo", service::get(Svc))
.route("/echo", service::get::<_, Body>(Svc))
.handle_error(handle_error::<hyper::Error>)
.route("/", get(unit));

Expand All @@ -189,7 +191,7 @@ fn service_handle_on_router_still_impls_routing_dsl() {
#[test]
fn layered() {
let app = Router::new()
.route::<_, Body>("/echo", get(unit))
.route("/echo", get::<_, Body, _>(unit))
.layer(timeout())
.handle_error(handle_error::<BoxError>);

Expand All @@ -199,7 +201,7 @@ fn layered() {
#[tokio::test] // async because of `.boxed()`
async fn layered_boxed() {
let app = Router::new()
.route::<_, Body>("/echo", get(unit))
.route("/echo", get::<_, Body, _>(unit))
.layer(timeout())
.boxed()
.handle_error(handle_error::<BoxError>);
Expand Down