Crate routefinder

source ·
Expand description

§Routefinder

use routefinder::{Router, Captures};
let mut router = Router::new();
router.add("/*", 1)?;
router.add("/hello", 2)?;
router.add("/:greeting", 3)?;
router.add("/hey/:world", 4)?;
router.add("/hey/earth", 5)?;
router.add("/:greeting/:world/*", 6)?;

assert_eq!(*router.best_match("/hey/earth").unwrap(), 5);
assert_eq!(
    router.best_match("/hey/mars").unwrap().captures().get("world"),
    Some("mars")
);
assert_eq!(router.matches("/hello").len(), 3);
assert_eq!(router.matches("/").len(), 1);
assert_eq!(
    router.best_match("/yo/planet/check/this/out").unwrap().captures().wildcard().unwrap(),
    "check/this/out",
);

Check out Router for a good starting place

Structs§

  • An individual key-value pair
  • Captured params and a wildcard
  • The output of a successful application of a RouteSpec to a str path, as well as references to any captures.
  • This struct represents the result of a reverse lookup from Captures to a RouteSpec
  • Routefinder’s representation of the parsed route
  • The top level struct for routefinder

Enums§

  • the internal representation of a parsed component of a route