Skip to main content

resolve

Function resolve 

Source
pub fn resolve<'a>(
    routes: &'a [RouteDef],
    action: &str,
    params: &Params,
    mode: ControllerMode,
) -> Result<(&'a RouteDef, ExtractedParams), WebError>
Expand description

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.

“Declaration order” matters: when two patterns can match the same action (e.g. "special" and "{id}"), the one declared first wins — list the more specific route earlier.

When no route fully matches, the error distinguishes:

  • WebError::MethodNotAllowed(methods): at least one route’s path pattern matched but its verb didn’t; methods is the (sorted, deduped) set of verbs those routes accept, which the caller surfaces as the Allow header.
  • WebError::NotFound: no route’s path pattern matched at all.