{"id":15687436,"url":"https://github.com/danielparks/matchgen","last_synced_at":"2025-06-30T00:36:18.225Z","repository":{"id":90026049,"uuid":"591498211","full_name":"danielparks/matchgen","owner":"danielparks","description":"Generate Rust functions to quickly map byte string prefixes to values","archived":false,"fork":false,"pushed_at":"2025-03-06T08:10:16.000Z","size":1553,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-09T06:51:02.938Z","etag":null,"topics":["parser","rust"],"latest_commit_sha":null,"homepage":"","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/danielparks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"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}},"created_at":"2023-01-20T22:48:07.000Z","updated_at":"2025-03-06T08:10:19.000Z","dependencies_parsed_at":"2024-03-09T19:28:22.640Z","dependency_job_id":"08b440a1-2070-4131-8b2e-23c2be3b5799","html_url":"https://github.com/danielparks/matchgen","commit_stats":{"total_commits":78,"total_committers":1,"mean_commits":78.0,"dds":0.0,"last_synced_commit":"12ad35656657a9aabe73c0d935cfbd4a921e38ee"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/danielparks/matchgen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielparks%2Fmatchgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielparks%2Fmatchgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielparks%2Fmatchgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielparks%2Fmatchgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielparks","download_url":"https://codeload.github.com/danielparks/matchgen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielparks%2Fmatchgen/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262689894,"owners_count":23349138,"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":["parser","rust"],"created_at":"2024-10-03T17:48:26.689Z","updated_at":"2025-06-30T00:36:18.182Z","avatar_url":"https://github.com/danielparks.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Generate functions to quickly map byte string prefixes to values\n\n[![docs.rs](https://img.shields.io/docsrs/matchgen)][docs.rs]\n[![Crates.io](https://img.shields.io/crates/v/matchgen)][crates.io]\n![Rust version 1.60+](https://img.shields.io/badge/Rust%20version-1.60%2B-success)\n\n[`TreeMatcher`] can be used from a [build script] to generate a matcher\nfunction that maps byte sequences to arbitrary values. It returns the mapped\nvalue (or `None`) and the remainder of the input.\n\nFor example, suppose you generate a [matcher for all HTML entities][htmlize]\ncalled `entity_matcher()`:\n\n```rust\nassert!(entity_matcher(b\"\u0026times;XYZ\") == (Some(\"×\"), b\"XYZ\".as_slice()));\n```\n\n  * The prefixes it checks do not all have to be the same length.\n  * If more than one prefix matches, it will return the longest one.\n  * If nothing matches, it will return `(None, \u0026input)`.\n\nSince the matchers only check the start of the input, you will want to use\n[`iter().position()`] or the [memchr crate][memchr] to find the start of a\npotential match.\n\nIt can also be configured to accept an iterator over bytes as input instead of\na slice.\n\n## Simple example\n\nTo create a matcher to handle the four basic HTML entities, use a build script\nlike the following:\n\n```rust\nuse matchgen::TreeMatcher;\nuse std::error::Error;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn Error\u003e\u003e {\n    TreeMatcher::new(\"pub fn entity_decode\", \"u8\")\n        .doc(\"Decode basic HTML entities.\")\n        .add(b\"\u0026amp;\", \"b'\u0026'\")\n        .add(b\"\u0026lt;\", \"b'\u003c'\")\n        .add(b\"\u0026gt;\", \"b'\u003e'\")\n        .add(b\"\u0026quot;\", \"b'\\\"'\")\n        .write_to_out_dir(\"matcher.rs\")?;\n\n    Ok(())\n}\n```\n\nTo use the matcher:\n\n```rust\ninclude!(concat!(env!(\"OUT_DIR\"), \"/matcher.rs\"));\n\nfn main() {\n    assert_eq!(\n      entity_decode(b\"\u0026amp; on \u0026amp; on\"),\n      (Some(b'\u0026'), b\" on \u0026amp; on\".as_slice()),\n    );\n}\n```\n\n## Development status\n\nThis is potentially stable. I’m letting it bake a while to see if I come up with\nnew features or better ways to accomplish the same thing before I release\nversion 1.0.\n\nI am open to [suggestions][issues].\n\n## License\n\nThis project dual-licensed under the Apache 2 and MIT licenses. You may choose\nto use either.\n\n  * [Apache License, Version 2.0](LICENSE-APACHE)\n  * [MIT license](LICENSE-MIT)\n\n### Contributions\n\nUnless you explicitly state otherwise, any contribution you submit as defined\nin the Apache 2.0 license shall be dual licensed as above, without any\nadditional terms or conditions.\n\n[docs.rs]: https://docs.rs/matchgen/latest/matchgen/\n[crates.io]: https://crates.io/crates/matchgen\n[`TreeMatcher`]: https://docs.rs/matchgen/latest/matchgen/struct.TreeMatcher.html\n[build script]: https://doc.rust-lang.org/cargo/reference/build-scripts.html\n[`iter().position()`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.position\n[memchr]: http://docs.rs/memchr\n[htmlize]: https://crates.io/crates/htmlize\n[issues]: https://github.com/danielparks/matchgen/issues\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielparks%2Fmatchgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielparks%2Fmatchgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielparks%2Fmatchgen/lists"}