nested_router 0.2.1

Nested route-recognizers
Documentation
  • Coverage
  • 0%
    0 out of 15 items documented0 out of 5 items with examples
  • Size
  • Source code size: 11.3 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.15 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Banyc/nested_router
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Banyc

Nested Router

Path segment matching for nested routers.

How to use

  1. Define your routes:

    fn route_list_1() -> (RouteList, RouteList) {
        let sub = RouteList {
            routes: vec![Route {
                path: ":id".to_string(),
                has_sub_routes: false,
            }],
        };
        let root = RouteList {
            routes: vec![
                Route {
                    path: ":id".to_string(),
                    has_sub_routes: true,
                },
                Route {
                    path: "about".to_string(),
                    has_sub_routes: false,
                },
            ],
        };
        (root, sub)
    }
    
  2. Use the two routers:

    let (root, sub) = route_list_1();
    
    let absolute_path = "/123/456";
    let relative_path = &absolute_path[1..];
    
    let RouteOutput {
        sub_path,
        route,
        params,
    } = root.route(relative_path).unwrap();
    assert_eq!(route.path, ":id");
    assert_eq!(params.get("id"), Some(&"123".to_string()));
    
    // Your business logic here for the first route
    
    let RouteOutput {
        sub_path,
        route,
        params,
    } = sub.route(&sub_path.unwrap()).unwrap();
    assert_eq!(route.path, ":id");
    assert_eq!(params.get("id"), Some(&"456".to_string()));
    assert_eq!(sub_path, None);
    
    // Your business logic here for the second route
    

Restrictions

  • Route::path should not capture wildcard with name "_sub_path" (crate::SUB_PATH_WILDCARD_NAME).