Skip to content

Commit

Permalink
explain that Router::merge only merges paths and fallback (#2316)
Browse files Browse the repository at this point in the history
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
  • Loading branch information
Emilgardis and davidpdrsn authored Nov 18, 2023
1 parent 0c7ff7c commit f7a0011
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion axum/src/docs/routing/merge.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions axum/src/routing/tests/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit f7a0011

Please sign in to comment.