Fix compile time regression by boxing routes internally (#404)

This is a reimplementation of #401 but with the new matchit based router.

Fixes #399
This commit is contained in:
David Pedersen
2021-10-24 20:52:42 +02:00
committed by GitHub
parent 1a764bb8d7
commit 0ee7379d4f
13 changed files with 203 additions and 242 deletions
+2 -4
View File
@@ -6,7 +6,6 @@
use axum::{
handler::{get, post},
routing::BoxRoute,
Json, Router,
};
use tower_http::trace::TraceLayer;
@@ -32,7 +31,7 @@ async fn main() {
/// Having a function that produces our app makes it easy to call it from tests
/// without having to create an HTTP server.
#[allow(dead_code)]
fn app() -> Router<BoxRoute> {
fn app() -> Router {
Router::new()
.route("/", get(|| async { "Hello, World!" }))
.route(
@@ -43,7 +42,6 @@ fn app() -> Router<BoxRoute> {
)
// We can still add middleware
.layer(TraceLayer::new_for_http())
.boxed()
}
#[cfg(test)]
@@ -59,7 +57,7 @@ mod tests {
async fn hello_world() {
let app = app();
// `BoxRoute<Body>` implements `tower::Service<Request<Body>>` so we can
// `Router` implements `tower::Service<Request<Body>>` so we can
// call it like any tower service, no need to run an HTTP server.
let response = app
.oneshot(Request::builder().uri("/").body(Body::empty()).unwrap())