Skip to main content

Module routing

Module routing 

Source
Expand description

Route resolution helpers — matching a request path + verb against a controller’s &[RouteDef] and extracting the path/query/body parameters. Used by the #[controller] macro’s generated dispatch; exposed for tools and tests that need to resolve routes directly.

Functions§

covering_family
Which of prefixes covers mount — by the same rule the families block of app_routes! applies at compile time, so a boot-time check written against this cannot disagree with the compile-time one: segment-aligned ("api" covers "api/things", never "apiary"), the longest covering prefix wins (so "api/auth" carves its subtree out of "api"), a trailing * reads as the prefix before it, and the root ("" or "*") covers every mount. Returns the winning prefix as it was given, so the caller can look it up in its own table. On two prefixes that normalise identically, the later one wins, as in the macro.
family_segments
The segments of a mount path or family prefix, normalised exactly as RouterBuilder::add_route and the families block of app_routes! normalise them: surrounding slashes trimmed, empty segments dropped, a trailing * (the catch-all sugar) removed — so "api/*", "/api/" and "api" are the same prefix, and "" / "*" is the root.
match_pattern
Match a route pattern against an action path. Returns extracted path parameters if matched.
param_is_required
Whether an absent value for param makes the request a 400.
resolve
Main route resolution function. Tries each route in declaration order and returns the first whose path pattern and verb both match, along with its extracted parameters.