2 unstable releases

0.8.0 Nov 16, 2023
0.7.2 Sep 3, 2023

#1993 in Procedural macros

Download history 38295/week @ 2024-01-29 44287/week @ 2024-02-05 42462/week @ 2024-02-12 43032/week @ 2024-02-19 51351/week @ 2024-02-26 54268/week @ 2024-03-04 41494/week @ 2024-03-11 43015/week @ 2024-03-18 48986/week @ 2024-03-25 58054/week @ 2024-04-01 59440/week @ 2024-04-08 62844/week @ 2024-04-15 59684/week @ 2024-04-22 60840/week @ 2024-04-29 56607/week @ 2024-05-06 69387/week @ 2024-05-13

248,011 downloads per month
Used in 200 crates (via quote-use)

MIT license

19KB
363 lines

Use statements in quote!

Crates.io Version CI Docs.rs Documentation

Description

Macro to simplify using Types in the quote! macro.

Usage

The quote_use! macro can be used just like quote!, but with the added functionality of adding use statements at the top:

quote_use!{
    use std::fs::read;
    
    read("src/main.rs")
}

This will expand to the equivalent statement using quote!:

quote!{
    ::std::fs::read::read("src/main.rs")
}

Prelude

This also allows to use contents of the rust prelude directly:

quote_use!{
    Some("src/main.rs")
}

Overriding prelude

When you want to use your own type instead of the prelude type this can be achieved by simply importing it like so

quote_use!{
    use anyhow::Result;
                                                                                                             
    Result
}

Different preludes

By default quote_use! uses the std prelude for 2021 edition, but this can be configured via features, and also completely disabled.

Other quote macros

There are also variants for other quote macros from syn and quote:

Auto namespacing idents

Until Span::def_site is stabilized, identifiers in e.g. let bindings in proc-macro expansions can collide with e.g. constants.

To circumvent this you can enable the feature namespace_idents which will replace all identifiers with autonamespaced ones using the pattern "__{crate_name}_{ident}".

Dependencies

~0.4–0.9MB
~21K SLoC