Panic instead of silently discarding fallbacks (#529)

This introduces two new possible panics when constructing routers:

- If merging two routers that each have a fallback. Previously that left
  side fallback would be silently discarded.
- If nesting a router that has a fallback. Previously it would be
  silently discarded.

Overall this should make things more explicit and users shouldn't have
to worry "why isn't my fallback" working.

Fixes #488
This commit is contained in:
David Pedersen
2021-11-18 22:19:06 +01:00
committed by GitHub
parent badbb14cce
commit 1d94d75c57
7 changed files with 38 additions and 67 deletions
+8 -3
View File
@@ -189,14 +189,17 @@ where
let Router {
mut routes,
node,
// discard the fallback of the nested router
fallback: _,
fallback,
// nesting a router that has something nested at root
// doesn't mean something is nested at root in _this_ router
// thus we don't need to propagate that
nested_at_root: _,
} = router;
if let Fallback::Custom(_) = fallback {
panic!("Cannot nest `Router`s that has a fallback");
}
for (id, nested_path) in node.route_id_to_path {
let route = routes.remove(&id).unwrap();
let full_path = if &*nested_path == "/" {
@@ -253,7 +256,9 @@ where
(Fallback::Default(_), pick @ Fallback::Default(_)) => pick,
(Fallback::Default(_), pick @ Fallback::Custom(_)) => pick,
(pick @ Fallback::Custom(_), Fallback::Default(_)) => pick,
(Fallback::Custom(_), pick @ Fallback::Custom(_)) => pick,
(Fallback::Custom(_), Fallback::Custom(_)) => {
panic!("Cannot merge two `Router`s that both have a fallback")
}
};
self.nested_at_root = self.nested_at_root || nested_at_root;