Coder Social home page Coder Social logo

zihantype / macro-v Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 19 KB

Attribute macro for making the visibility of the `macro_rules!` macro the same as other items. -- 一个让声名式宏的可见性和其他 item 一样的属性宏

License: MIT License

Rust 100.00%

macro-v's Introduction

macro-v

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

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_v(pub(crate))]
macro_rules! example_macro { () => {}; }

... will expand to this:

#[doc(hidden)]
macro_rules! __example_macro_2228885075611141983 { () => {}; }

#[doc(inline)]
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:

#[doc(hidden)]
#[macro_export]
macro_rules! __example_macro_2228885075611141983 { () => {}; }

#[doc(inline)]
pub use __example_macro_2228885075611141983 as example_macro;

Limitations

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.

macro-v's People

Contributors

zihantype avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.