GithubHelp home page GithubHelp logo

prom-attire-rs's Introduction

prom-attire travis-badge cargo-badge license-badge rust-version-badge

Procedural Macro Attributes

For when you need the best dressed procedural macro.

Developing

This project uses clippy and denies warnings in CI builds. To ensure your changes will be accepted please check them with cargo clippy (available via cargo install clippy on nightly rust) before submitting a pull request (along with cargo test as usual).

Both the nightly date and clippy version used in CI are pinned in the .travis.yml as clippy sometimes breaks for a few days after a new nightly is published, feel free to update to a new known good pair anytime as part of a pull request.

Why Three Crates

Why not three crates?

One issue with current procedural macros is that crates defining procedural macros can't use their own procedural macros. In this case prom-attire wants to have some attributes controlling how it parses the attributes (at the moment, only the top level "scope" attribute identifier, i.e. the value attire in #[attire(scope = shoes)]), obviously prom-attire will need to parse these attributes out to get the details it needs, but the entire point of prom-attire is to make parsing attributes pain-free, having a manual parser in prom-attire itself mean any upgrades to the parsing code generated by prom-attire would probably have to be duplicated in the parsing code inside prom-attire itself.

Luckily there is a solution, by using three crates ;-)

The base is prom-attire-impl, this implements the entirety of the procedural derive, but does not itself define a procedural derive macro. Instead it exports a single function taking in the AST provided to a procedural derive and some configuration and returns the derived implementation.

Next prom-attire-bootstrap defines a simple procedural derive macro FromAttributesBootstrap that calls into prom-attire-impl with a hardcoded configuration.

Finally prom-attire defines a slightly more complicated procedural derive macro (FromAttributes) that parses some attributes (using a parser derived with FromAttributesBootstrap), then calls into prom-attire-impl with a configuration derived from those parsed attributes. This is the "public" entrypoint to the crates, technically the others could be used but they're unlikely to be useful.

So, in the end prom-attire is a crate defining a procedural derive macro, to help developers write procedural derive macros, that uses a procedural derive in its implementation (no, that is not inception).

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.

prom-attire-rs's People

Contributors

nemo157 avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

ugurlu2001

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.