{"id":13595401,"url":"https://github.com/rust-phf/rust-phf","last_synced_at":"2025-05-14T09:06:18.090Z","repository":{"id":13306627,"uuid":"15992970","full_name":"rust-phf/rust-phf","owner":"rust-phf","description":"Compile time static maps for Rust","archived":false,"fork":false,"pushed_at":"2025-02-02T10:06:12.000Z","size":2980,"stargazers_count":1916,"open_issues_count":32,"forks_count":126,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-05-06T23:44:27.573Z","etag":null,"topics":["rust"],"latest_commit_sha":null,"homepage":"","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/rust-phf.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-01-17T07:23:04.000Z","updated_at":"2025-05-02T12:48:43.000Z","dependencies_parsed_at":"2023-01-13T17:25:06.935Z","dependency_job_id":"c64437fb-6fcd-4aa9-a393-76147aaf4072","html_url":"https://github.com/rust-phf/rust-phf","commit_stats":{"total_commits":604,"total_committers":67,"mean_commits":9.014925373134329,"dds":0.3443708609271523,"last_synced_commit":"999e6a260f03d82aa9d159465113294e7ed019e7"},"previous_names":["sfackler/rust-phf"],"tags_count":83,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-phf%2Frust-phf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-phf%2Frust-phf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-phf%2Frust-phf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-phf%2Frust-phf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rust-phf","download_url":"https://codeload.github.com/rust-phf/rust-phf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252788523,"owners_count":21804285,"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":["rust"],"created_at":"2024-08-01T16:01:49.403Z","updated_at":"2025-05-14T09:06:17.992Z","avatar_url":"https://github.com/rust-phf.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":["Rust libraries"],"readme":"# Rust-PHF\n\n[![CI](https://github.com/rust-phf/rust-phf/actions/workflows/ci.yml/badge.svg)](https://github.com/rust-phf/rust-phf/actions/workflows/ci.yml) [![Latest Version](https://img.shields.io/crates/v/phf.svg)](https://crates.io/crates/phf)\n\n[Documentation](https://docs.rs/phf)\n\nRust-PHF is a library to generate efficient lookup tables at compile time using\n[perfect hash functions](http://en.wikipedia.org/wiki/Perfect_hash_function).\n\nIt currently uses the\n[CHD algorithm](http://cmph.sourceforge.net/papers/esa09.pdf) and can generate\na 100,000 entry map in roughly .4 seconds.\n\nMSRV (minimum supported rust version) is Rust 1.61.\n\n## Usage\n\nPHF data structures can be constructed via either the procedural\nmacros in the `phf_macros` crate or code generation supported by the\n`phf_codegen` crate.\n\nTo compile the `phf` crate with a dependency on\nlibcore instead of libstd, enabling use in environments where libstd\nwill not work, set `default-features = false` for the dependency:\n\n```toml\n[dependencies]\n# to use `phf` in `no_std` environments\nphf = { version = \"0.11\", default-features = false }\n```\n\n### phf_macros\n\n```rust\nuse phf::phf_map;\n\n#[derive(Clone)]\npub enum Keyword {\n    Loop,\n    Continue,\n    Break,\n    Fn,\n    Extern,\n}\n\nstatic KEYWORDS: phf::Map\u003c\u0026'static str, Keyword\u003e = phf_map! {\n    \"loop\" =\u003e Keyword::Loop,\n    \"continue\" =\u003e Keyword::Continue,\n    \"break\" =\u003e Keyword::Break,\n    \"fn\" =\u003e Keyword::Fn,\n    \"extern\" =\u003e Keyword::Extern,\n};\n\npub fn parse_keyword(keyword: \u0026str) -\u003e Option\u003cKeyword\u003e {\n    KEYWORDS.get(keyword).cloned()\n}\n```\n\n```toml\n[dependencies]\nphf = { version = \"0.11\", features = [\"macros\"] }\n```\n\n#### Note\n\nCurrently, the macro syntax has some limitations and may not\nwork as you want. See [#183] or [#196] for example.\n\n[#183]: https://github.com/rust-phf/rust-phf/issues/183\n[#196]: https://github.com/rust-phf/rust-phf/issues/196\n\n### phf_codegen\n\nTo use `phf_codegen` on build.rs, you have to add dependencies under `[build-dependencies]`:\n\n```toml\n[build-dependencies]\nphf = { version = \"0.11.1\", default-features = false }\nphf_codegen = \"0.11.1\"\n```\n\nThen put code on build.rs:\n\n```rust\nuse std::env;\nuse std::fs::File;\nuse std::io::{BufWriter, Write};\nuse std::path::Path;\n\nfn main() {\n    let path = Path::new(\u0026env::var(\"OUT_DIR\").unwrap()).join(\"codegen.rs\");\n    let mut file = BufWriter::new(File::create(\u0026path).unwrap());\n\n    write!(\n        \u0026mut file,\n        \"static KEYWORDS: phf::Map\u003c\u0026'static str, Keyword\u003e = {}\",\n        phf_codegen::Map::new()\n            .entry(\"loop\", \"Keyword::Loop\")\n            .entry(\"continue\", \"Keyword::Continue\")\n            .entry(\"break\", \"Keyword::Break\")\n            .entry(\"fn\", \"Keyword::Fn\")\n            .entry(\"extern\", \"Keyword::Extern\")\n            .build()\n    )\n    .unwrap();\n    write!(\u0026mut file, \";\\n\").unwrap();\n}\n```\n\nand lib.rs:\n\n```rust\n#[derive(Clone)]\nenum Keyword {\n    Loop,\n    Continue,\n    Break,\n    Fn,\n    Extern,\n}\n\ninclude!(concat!(env!(\"OUT_DIR\"), \"/codegen.rs\"));\n\npub fn parse_keyword(keyword: \u0026str) -\u003e Option\u003cKeyword\u003e {\n    KEYWORDS.get(keyword).cloned()\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-phf%2Frust-phf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frust-phf%2Frust-phf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-phf%2Frust-phf/lists"}