explain that Router::merge only merges paths and fallback (#2316)

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
This commit is contained in:
Emil Gardström 2023-11-18 13:36:25 +01:00 committed by GitHub
parent 0c7ff7c76b
commit f7a0011ea5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -1,4 +1,4 @@
Merge two routers into one.
Merge the paths and fallbacks of two routers into a single [`Router`].
This is useful for breaking apps into smaller pieces and combining them
into one.
@ -71,6 +71,11 @@ let app = Router::new()
# let _: axum::Router = app;
```
# Merging routers with fallbacks
When combining [`Router`]s with this method, the [fallback](Router::fallback) is also merged.
However only one of the routers can have a fallback.
# Panics
- If two routers that each have a [fallback](Router::fallback) are merged. This

View file

@ -135,6 +135,8 @@ async fn layer_and_handle_error() {
let res = client.get("/timeout").send().await;
assert_eq!(res.status(), StatusCode::REQUEST_TIMEOUT);
let res = client.get("/foo").send().await;
assert_eq!(res.status(), StatusCode::OK);
}
#[crate::test]