{"id":51218251,"url":"https://github.com/fast/macroweave","last_synced_at":"2026-06-28T05:32:18.633Z","repository":{"id":365856470,"uuid":"1274036845","full_name":"fast/macroweave","owner":"fast","description":"Table-driven Rust code templates.","archived":false,"fork":false,"pushed_at":"2026-06-25T16:52:42.000Z","size":123,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-25T17:04:34.345Z","etag":null,"topics":["proc-macro","rust-lang","template"],"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/fast.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-06-19T05:52:10.000Z","updated_at":"2026-06-25T16:48:23.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/fast/macroweave","commit_stats":null,"previous_names":["fast/macro-template","fast/macroweave"],"tags_count":3,"template":false,"template_full_name":"fast/template","purl":"pkg:github/fast/macroweave","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Fmacroweave","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Fmacroweave/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Fmacroweave/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Fmacroweave/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fast","download_url":"https://codeload.github.com/fast/macroweave/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Fmacroweave/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34878963,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-28T02:00:05.809Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["proc-macro","rust-lang","template"],"created_at":"2026-06-28T05:32:17.865Z","updated_at":"2026-06-28T05:32:18.628Z","avatar_url":"https://github.com/fast.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# macroweave\n\n[![Crates.io][crates-badge]][crates-url]\n[![Documentation][docs-badge]][docs-url]\n[![MSRV 1.85][msrv-badge]](https://www.whatrustisit.com)\n[![Apache 2.0 licensed][license-badge]][license-url]\n[![Build Status][actions-badge]][actions-url]\n\n[crates-badge]: https://img.shields.io/crates/v/macroweave.svg\n[crates-url]: https://crates.io/crates/macroweave\n[docs-badge]: https://img.shields.io/docsrs/macroweave\n[docs-url]: https://docs.rs/macroweave\n[msrv-badge]: https://img.shields.io/badge/MSRV-1.85-green?logo=rust\n[license-badge]: https://img.shields.io/crates/l/macroweave\n[license-url]: https://www.apache.org/licenses/LICENSE-2.0\n[actions-badge]: https://github.com/fast/macroweave/workflows/CI/badge.svg\n[actions-url]: https://github.com/fast/macroweave/actions?query=workflow%3ACI\n\n\u003c!-- macroweave-docs-start --\u003e\n\n`macroweave` provides procedural macros for generating repeated Rust code from compact, table-driven inputs.\n\n## Motivation\n\n`macroweave` is for repetition that has to become Rust syntax, not runtime control flow. You write the choices once, name the columns, and use those names in Rust syntax.\n\nThat is the table-driven case `macroweave` is built around:\n\n```rust\nuse macroweave::repeat;\n\ntrait ReadLe {\n    fn read_le(input: \u0026[u8]) -\u003e Self;\n}\n\nrepeat!((Ty, Width) in [\n    (u16, 2),\n    (u32, 4),\n    (u64, 8),\n] {\n    impl ReadLe for Ty {\n        fn read_le(input: \u0026[u8]) -\u003e Self {\n            Ty::from_le_bytes(input[..Width].try_into().unwrap())\n        }\n    }\n});\n\nassert_eq!(u16::read_le(\u0026[0x34, 0x12]), 0x1234);\nassert_eq!(u32::read_le(\u0026[1, 0, 0, 0]), 1);\n```\n\nThis cannot be written as an ordinary for-loop because `Ty` and `Width` need to be substituted as tokens before the generated code is type-checked.\n\n# Whole-body repetition\n\nWithout splice syntax, [`repeat!`] emits the whole body once per input row:\n\n```rust\nuse macroweave::repeat;\n\ntrait TypeName {\n    const NAME: \u0026'static str;\n}\n\nrepeat!((Ty, Name) in [\n    (u8, \"u8\"),\n    (u16, \"u16\"),\n    (u32, \"u32\"),\n] {\n    impl TypeName for Ty {\n        const NAME: \u0026'static str = Name;\n    }\n});\n\nassert_eq!(\u003cu8 as TypeName\u003e::NAME, \"u8\");\nassert_eq!(\u003cu16 as TypeName\u003e::NAME, \"u16\");\nassert_eq!(\u003cu32 as TypeName\u003e::NAME, \"u32\");\n```\n\n# Partial repetition\n\nWhen only part of a surrounding construct should repeat, use [`splice!`] and put that part in `#( ... )*`. A single separator can be written before `*`, such as `#( ... ),*` for comma-separated output:\n\n```rust\nuse macroweave::splice;\n\nfn keyword_code(text: \u0026str) -\u003e Option\u003cu8\u003e {\n    splice!((Pat, Code) in [\n        (\"async\", 1u8),\n        (\"await\", 2u8),\n    ] {\n        match text {\n            #(Pat =\u003e Some(Code)),*,\n            _ =\u003e None,\n        }\n    })\n}\n\nassert_eq!(keyword_code(\"async\"), Some(1));\nassert_eq!(keyword_code(\"await\"), Some(2));\nassert_eq!(keyword_code(\"fn\"), None);\n```\n\nPlaceholders are substituted only inside the splice body, and the surrounding tokens are emitted once. Surrounding identifiers stay literal, even when they have the same name as a placeholder. If a value should vary, place it in the splice body.\n\n`#( ..., )*` and `#( ... ),*` are different: the latter does not produce a trailing comma. This matches delimiter repetition in `macro_rules!`.\n\n# Syntax notes\n\n- Bind placeholders as bare identifiers, such as `Ty` or `Name`.\n- Tuple rows bind multiple placeholders, and `_` skips a row value.\n- Row values can contain one or more Rust tokens. Top-level commas separate rows.\n- Nested invocations are supported. Use different placeholder names at each level.\n\n\u003c!-- macroweave-docs-end --\u003e\n\n## Minimum Rust version policy\n\nThis crate's minimum supported `rustc` version is `1.85.0`.\n\nThe minimum Rust version can be increased in minor version updates. For example, if crate `1.0` requires Rust 1.85.0, then all `1.0.z` releases also support Rust 1.85.0 or newer, while `1.y` for `y \u003e 0` may require a newer compiler.\n\n## License\n\nThis project is licensed under [Apache License, Version 2.0][license-url].\n\n## Origins\n\n`macroweave` resulted from a ScopeDB code refactor. ScopeDB has used [`match-template`](https://github.com/tisonkun/match-template/) for variant/type match arms and [`macro_find_and_replace`](https://github.com/lord-ne/rust-macro-find-and-replace/) for repeating Rust fragments over type lists. While reviewing their macro usages, I found that I wanted the same thing in both places: write the choices once, name the columns, and use those names in Rust syntax. There was no existing solution fitting that shape.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffast%2Fmacroweave","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffast%2Fmacroweave","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffast%2Fmacroweave/lists"}