Expand description
§use-route
Small route and path utilities for RustUse.
§Experimental
use-route is experimental while the use-web workspace remains below 0.3.0. Expect small API adjustments during the first release wave.
§Example
use use_route::{extract_route_params, matches_route_pattern, normalize_route};
assert_eq!(normalize_route("//users//42/"), "/users/42");
assert!(matches_route_pattern("/users/:id", "/users/42"));
assert_eq!(extract_route_params("/users/:id", "/users/42")[0].value, "42");§Scope
- Route normalization and joining.
- Simple segment splitting and depth counting.
- Lightweight
:parampattern matching.
§Non-goals
- Full routers.
- Middleware.
- Regex route engines.
- Server implementations.
§License
Licensed under either of the following, at your option:
- Apache License, Version 2.0
- MIT license
Structs§
- Route
Param - A captured route parameter.
- Route
Segment - A normalized route segment.
Functions§
- extract_
route_ params - Extracts named route parameters when a pattern matches.
- is_
absolute_ route - Returns
truewhen the route is absolute. - join_
routes - Joins two route fragments with exactly one slash.
- matches_
route_ pattern - Returns
truewhen a simple:parampattern matches the path. - normalize_
route - Normalizes repeated slashes and removes trailing slashes except for the root route.
- route_
depth - Returns the number of non-empty route segments.
- split_
route - Splits a route into normalized segments.