{"id":19098336,"url":"https://github.com/ivowingelaar/uri_path_router","last_synced_at":"2026-06-25T10:31:30.052Z","repository":{"id":57697992,"uuid":"499081326","full_name":"IvoWingelaar/uri_path_router","owner":"IvoWingelaar","description":"A proc-macro crate that generates flattened enums for routing","archived":false,"fork":false,"pushed_at":"2022-06-02T10:47:46.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-05T07:03:43.702Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IvoWingelaar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-02T09:56:52.000Z","updated_at":"2022-06-02T09:57:54.000Z","dependencies_parsed_at":"2022-09-26T21:02:00.137Z","dependency_job_id":null,"html_url":"https://github.com/IvoWingelaar/uri_path_router","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IvoWingelaar%2Furi_path_router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IvoWingelaar%2Furi_path_router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IvoWingelaar%2Furi_path_router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IvoWingelaar%2Furi_path_router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IvoWingelaar","download_url":"https://codeload.github.com/IvoWingelaar/uri_path_router/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240152133,"owners_count":19756029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T03:45:05.014Z","updated_at":"2026-05-27T10:30:16.784Z","avatar_url":"https://github.com/IvoWingelaar.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# uri_path_router\n\nThis library provides a procedural macro that uses a small domain specific\nlanguage to create a naive parser that can translate the path of a URI into a\nvariant of a flattened `enum` for routing purposes.\n\nThe generated logic is basically a big nested `match` that greedily accepts an\ninput `\u0026str`, splits it into segments separated by `/` characters, and outputs\na variant of the `enum`, optionally capturing segments of the path if they are\nspecified as variables.\n\n# Usage\n\nYou write this:\n\n```rust\nuse uri_path_router::route;\n\nroute! {\n    Router,\n    \"foo\" =\u003e VariantA,\n    \"bar\" =\u003e VariantBar {\n        \"x\" =\u003e BarX,\n        var =\u003e BarWithVariable(var)\n    },\n    \"nested\" / \"syntax\" / \"demonstration\" =\u003e Nested,\n}\n```\n\nThe macro will produce a flattened `enum` like this:\n\n```rust\npub enum Router\u003c'a\u003e {\n    VariantA,\n    VariantBar,\n    BarX,\n    BarWithVariable { var: \u0026'a str },\n    Nested,\n}\n```\n\nNote that the `enum` only captures the variable when a variant specifies it,\nand always does so as a borrow and as such without any allocations.\nTo convert a `\u0026str` into a variant, use `TryFrom`:\n\n```rust\nassert_eq!(Router::try_from(\"/foo\"), Ok(Router::VariantA));\nassert_eq!(Router::try_from(\"/bar\"), Ok(Router::VariantBar));\nassert_eq!(Router::try_from(\"/bar/x\"), Ok(Router::BarX));\nassert_eq!(\n    Router::try_from(\"/bar/not-x\"),\n    Ok(Router::BarWithVariable { var: \"not-x\" })\n);\nassert_eq!(Router::try_from(\"/whatever\"), Err(()));\nassert_eq!(\n    Router::try_from(\"/nested/syntax/demonstration\"),\n    Ok(Router::Nested)\n);\n```\n\nA nifty feature of this crate is that documentation is auto-generated for\nevery variant of the `enum` describing what pattern matches it.\nYou can check this out by hovering over the variant in your IDE (assuming you\nhave `rust-analyzer` or something similar configured to display tooltips), or\nby running `cargo doc` on your crate and searching for the generated `enum`.\n\n# License\n\nThis library is provided under the MIT license. See [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivowingelaar%2Furi_path_router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivowingelaar%2Furi_path_router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivowingelaar%2Furi_path_router/lists"}