#visibility #macro-rules #attributes #items #pub #macro-use #macro-export

macro macro-v

Attribute macro for making the visibility of the macro_rules! macro the same as other items

5 releases

0.1.4 Aug 8, 2023
0.1.3 Mar 19, 2023
0.1.2 Mar 18, 2023
0.1.1 Mar 12, 2023
0.1.0 Mar 11, 2023

#1596 in Procedural macros

Download history 21/week @ 2024-03-11 7/week @ 2024-03-18 5/week @ 2024-03-25 24/week @ 2024-04-01 7/week @ 2024-04-08 1/week @ 2024-04-15 4/week @ 2024-05-13 14/week @ 2024-05-20 10/week @ 2024-05-27 10/week @ 2024-06-03 13/week @ 2024-06-10 14/week @ 2024-06-17 15/week @ 2024-06-24

52 downloads per month
Used in 5 crates (2 directly)


115 lines


Crates.io version docs.rs docs

This crate provides an attribute macro for making the visibility of the macro_rules! macro the same as other items.

The visibility of declarative macros is not consistent with the behavior of other items in rust, necessitating the use of #[macro_use] and #[macro_export] instead of pub or pub(...), such inconsistencies make the mental burden and cognitive cost significant. Now with this crate, you are allowed to use #[macro_v] or #[macro_v(pub)] or #[macro_v(pub(...))] on any macro_rules! macro, giving declarative macros the same visibility as other items, no more writing confusing #[macro_use] and #[macro_export].


Inspired by macro-vis and even named after a part of it, but there are two problems of macro-vis:

  1. you have to add #![allow(uncommon_codepoints)].

  2. the modified macro is shown in the documentation as a function instead of a macro.

To solve these two problems, I've reimplemented an attribute macro.

How it works

It's very simple, see the code:

macro_rules! example_macro { () => {}; }

... will expand to this:

macro_rules! __example_macro_2228885075611141983 { () => {}; }

pub(crate) use __example_macro_2228885075611141983 as example_macro;

If you are using #[macro_v(pub)], then the expanded code will then have #[macro_export] added to it:

macro_rules! __example_macro_2228885075611141983 { () => {}; }

pub use __example_macro_2228885075611141983 as example_macro;


Because of using #[doc(hidden)], you must use #[doc(inline)] attribute when re-exporting, otherwise re-exported macro won't be visible in the document. When using #[macro_v], #[doc(inline)] will be added automatically, but if you want to manually re-export the macro, you must also manually add #[doc(inline)], which is the only problem.


~19K SLoC