{"id":13594963,"url":"https://github.com/mathematic-inc/unfmt","last_synced_at":"2025-05-15T23:06:40.499Z","repository":{"id":221984148,"uuid":"755962232","full_name":"mathematic-inc/unfmt","owner":"mathematic-inc","description":"A compile-time pattern matching library that reverses the interpolation process of `format!`.","archived":false,"fork":false,"pushed_at":"2025-05-14T23:58:59.000Z","size":236,"stargazers_count":161,"open_issues_count":5,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-15T00:39:03.055Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mathematic-inc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"mathematic-inc"}},"created_at":"2024-02-11T15:42:42.000Z","updated_at":"2025-03-30T20:30:32.000Z","dependencies_parsed_at":"2024-04-06T19:28:07.342Z","dependency_job_id":"ba7aeb8c-a199-47c1-b8a2-fa8c3ab1537b","html_url":"https://github.com/mathematic-inc/unfmt","commit_stats":null,"previous_names":["mathematic-inc/unfmt"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathematic-inc%2Funfmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathematic-inc%2Funfmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathematic-inc%2Funfmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathematic-inc%2Funfmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathematic-inc","download_url":"https://codeload.github.com/mathematic-inc/unfmt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254257350,"owners_count":22040439,"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-08-01T16:01:41.614Z","updated_at":"2025-05-15T23:06:35.477Z","avatar_url":"https://github.com/mathematic-inc.png","language":"Rust","readme":"# unfmt\n\n[![crates.io](https://img.shields.io/crates/v/unfmt?style=flat-square)](https://crates.io/crates/unfmt)\n[![license](https://img.shields.io/crates/l/unfmt?style=flat-square)](https://github.com/mathematic-inc/unfmt)\n[![ci](https://img.shields.io/github/actions/workflow/status/mathematic-inc/unfmt/ci.yaml?label=ci\u0026style=flat-square)](https://github.com/mathematic-inc/unfmt/actions/workflows/ci.yaml)\n[![docs](https://img.shields.io/docsrs/unfmt?style=flat-square)](https://docs.rs/unfmt/latest/unfmt/)\n\n`unfmt` is a compile-time pattern matching library that reverses the\ninterpolation process of `format!`.\n\nYou can think of it as an extremely lightweight regular expression engine\nwithout the runtime pattern-compilation cost.\n\n## Installation\n\n```sh\ncargo add -D unfmt\n```\n\n## Usage\n\n```rs\nlet value = \"My name is Rho.\";\n\n// Unnamed captures are returned as tuples.\nassert_eq!(\n    unformat!(\"My {} is {}.\", value),\n    Some((\"name\", \"Rho\"))\n);\n\n// You can put indices as well; just make sure ALL captures use indices\n// otherwise it's not well defined.\nassert_eq!(\n    unformat!(\"My {1} is {0}.\", value),\n    Some((\"Rho\", \"name\"))\n);\n\n// You can also name captures using variables, but make sure you check the\n// return is not None.\nlet mut subject = None;\nlet mut object = None;\nassert_eq!(\n    unformat!(\"My {subject} is {object}.\", value),\n    Some(())\n);\nassert_eq!((subject, object), (Some(\"name\"), Some(\"Rho\")));\n\n// If you want to ensure the entire string matches, you can add `true` to the end of the macro.\nassert_eq!(unformat!(\"{1} is {0}\", value, true), None);\n\n// If a type implements `FromStr`, you can use it as a type argument. This\n// is written as `{:Type}`.\nassert_eq!(\n    unformat!(\"Listening on {:url::Url}\", \"Listening on http://localhost:3000\"),\n    Some((url::Url::from_str(\"http://localhost:3000\").unwrap(),))\n);\n```\n\nIn general, captures are written as `{\u003cindex-or-variable\u003e:\u003ctype\u003e}`. Multiple\ncaptures in a row (i.e. `{}{}`) are not supported as they aren't well-defined.\n\n## Limitations\n\n- There is no backtracking.\n","funding_links":["https://github.com/sponsors/mathematic-inc"],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathematic-inc%2Funfmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathematic-inc%2Funfmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathematic-inc%2Funfmt/lists"}