Skip to main content

match_pattern

Function match_pattern 

Source
pub fn match_pattern(
    pattern: &str,
    path: &str,
) -> Option<HashMap<String, String>>
Expand description

Match a route pattern against an action path. Returns extracted path parameters if matched.

Both sides are viewed as lists of non-empty path segments. A literal segment or {name} token is required — it has no match when there’s no segment to fill it, so match_pattern("{id}", "") is None. (A controller that wants to serve its collection root declares "" => ….)

A trailing {...name} token is a rest parameter: it captures the remainder of the path (slashes included) and matches zero or more segments — match_pattern("{...path}", "") is Some({path: ""}), and "{folder_id}/{...path}" matches "abc" (path == "") and "abc/x/y" (path == "x/y") but not "" (the required folder_id has no segment). The #[controller] macro enforces that {...name} appears at most once and only as the final token; this function trusts that and only inspects the last token.