{"id":16851883,"url":"https://github.com/cad97/macro_pub","last_synced_at":"2025-04-11T07:00:33.484Z","repository":{"id":42045605,"uuid":"482063240","full_name":"CAD97/macro_pub","owner":"CAD97","description":null,"archived":false,"fork":false,"pushed_at":"2022-04-15T21:36:03.000Z","size":10,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T04:51:23.007Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://lib.rs/crates/macro_pub","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CAD97.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-15T19:25:18.000Z","updated_at":"2024-12-13T11:21:56.000Z","dependencies_parsed_at":"2022-08-12T03:20:14.237Z","dependency_job_id":null,"html_url":"https://github.com/CAD97/macro_pub","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CAD97%2Fmacro_pub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CAD97%2Fmacro_pub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CAD97%2Fmacro_pub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CAD97%2Fmacro_pub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CAD97","download_url":"https://codeload.github.com/CAD97/macro_pub/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248358555,"owners_count":21090402,"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-10-13T13:33:58.848Z","updated_at":"2025-04-11T07:00:33.430Z","avatar_url":"https://github.com/CAD97.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"`#[macro_pub]` is a replacement for `#[macro_export]` which provides normal\nvisibility rules for `macro_rules!` macros.\n\nIf you want the macro to not have world-public visibility, then use\n`pub(in path)` syntax in the attribute, e.g. `#[macro_pub(crate)]`.\n\n# How\n\nIf you `use` a legacy scoped macro, it \"mounts\" it to the normal visibility\nand can be used as a normal item from then on. So when you write\n\n```rust\n#[macro_pub(crate)]\nmacro_rules! my_macro {\n    () =\u003e {};\n}\n```\n\nit expands to something like\n\n```rust\nmacro_rules! macro_impl_279137529572831871236407390024221977230_my_macro {\n    () =\u003e {};\n}\npub(crate) use macro_impl_279137529572831871236407390024221977230_my_macro\n    as my_macro;\n```\n\nThe hash is the XXH3 hash of the annotated item's `TokenStream`, and is\nincluded to prevent name conflicts in the macro namespace.\n\nIf you do not specify a `pub(in path)` restriction, you instead get a\nworld-visible macro:\n\n```rust\n#[macro_export]\n#[doc(hidden)]\nmacro_rules! macro_impl_279137529572831871236407390024221977230_my_macro {\n    () =\u003e {};\n}\npub use macro_impl_279137529572831871236407390024221977230_my_macro\n    as my_macro;\n```\n\n# Documenting public macros\n\nUnfortunately, `#[doc(hidden)]` on the actual macro implementation hides\nany documentation attatched to it, `#[doc(inline)]`ing the `use` juts makes\nit hidden as well, and you can't attach documentation. Thus, on stable, your\nmacro will be included in the documentation just as a re-export:\n\n```rust\npub use macro_impl_279137529572831871236407390024221977230_my_macro\n    as my_macro;\n```\n\nand `macro_impl_279137529572831871236407390024221977230_my_macro` will not\nbe documented.\n\nIf you are on nightly, however, we can take advantage of nightly features\nin order to document the macro. In order to document your crate on nightly,\n`#[macro_pub]` requires `#![cfg_attr(doc, feature(decl_macro, rustc_attrs))]`\nand instead emits\n\n```rust\n#[cfg(doc)]\n#[rustc_macro_transparency = \"semitransparent\"]\npub macro my_macro {\n    () =\u003e {},\n}\n#[cfg(not(doc))]\n// the previous expansion\n```\n\nThis uses the unstable \"macros 2.0\" to define a macro with the legacy\n`macro_rules!` hygeine rules that obeys normal scoping rules and is\ndocumented cleanly by rustdoc.\n\n`macro_pub` automatically sniffs the rustc you're using to compile and\ndetermines if it can use decl_macro and rustc_attrs in this way. When these\nfeatures inevitably get changed, `macro_pub` will automatically fall back to\nthe stable solution. Additionally, if/when a direct solution to this problem\nis stabilized (e.g. `pub macro_rules!`, which has been discussed to do\nalmost exactly what this crate does), `macro_pub` will be updated to take\nadvantage of that on compatible rustc versions.\n\n# Examples\n\nIn a module with `pub(crate)` visibility:\n\n```rust\n#[macro_use]\nextern crate macro_pub;\n\nmod test {\n    #[macro_pub(crate)]\n    macro_rules! m {\n        () =\u003e {};\n    }\n}\n\ntest::m!();\n```\n\nWith `pub(self)` visibility, it can't be accessed outside the module:\n\n```rust\n#[macro_use]\nextern crate macro_pub;\n# fn main() {}\n\nmod test {\n    #[macro_pub(self)]\n    macro_rules! m {\n        () =\u003e {};\n    }\n}\n\ntest::m!(); //~ ERROR\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcad97%2Fmacro_pub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcad97%2Fmacro_pub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcad97%2Fmacro_pub/lists"}