fix doc tests

This commit is contained in:
David Pedersen
2022-06-29 21:32:41 +02:00
parent 23721f213f
commit 2c54bb5b3b
3 changed files with 3 additions and 19 deletions
+2 -2
View File
@@ -88,7 +88,7 @@ let serve_dir_service = get_service(ServeDir::new("public"))
)
});
let app = Router::new().nest("/public", serve_dir_service);
let app = Router::new().nest_service("/public", serve_dir_service);
# async {
# axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
# };
@@ -107,7 +107,7 @@ let app = Router::new()
.route("/foo/*rest", get(|uri: Uri| async {
// `uri` will contain `/foo`
}))
.nest("/bar", get(|uri: Uri| async {
.nest_service("/bar", get(|uri: Uri| async {
// `uri` will _not_ contain `/bar`
}));
# async {
-16
View File
@@ -184,22 +184,6 @@ let app = Router::new()
The static route `/foo` and the dynamic route `/:key` are not considered to
overlap and `/foo` will take precedence.
Take care when using [`Router::nest`] as it behaves like a wildcard route.
Therefore this setup panics:
```rust,should_panic
use axum::{routing::get, Router};
let app = Router::new()
// this is similar to `/api/*`
.nest("/api", get(|| async {}))
// which overlaps with this route
.route("/api/users", get(|| async {}));
# async {
# axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
# };
```
Also panics if `path` is empty.
## Nesting
+1 -1
View File
@@ -414,7 +414,7 @@ nested_route_test!(nest_3, nest = "", route = "/a/", expected = "/a/");
nested_route_test!(nest_4, nest = "/", route = "/", expected = "/");
nested_route_test!(nest_5, nest = "/", route = "/a", expected = "/a");
nested_route_test!(nest_6, nest = "/", route = "/a/", expected = "/a/");
nested_route_test!(nest_7, nest = "/a", route = "/", expected = "/a",);
nested_route_test!(nest_7, nest = "/a/", route = "/", expected = "/a");
nested_route_test!(nest_8, nest = "/a", route = "/a", expected = "/a/a");
nested_route_test!(nest_9, nest = "/a", route = "/a/", expected = "/a/a/");
nested_route_test!(nest_11, nest = "/a/", route = "/", expected = "/a/");