6 releases

0.8.4 Aug 25, 2024
0.8.3 Jul 8, 2024
0.8.0 Nov 16, 2023
0.7.2 Sep 3, 2023

#2284 in Procedural macros

Download history 89642/week @ 2024-07-26 82344/week @ 2024-08-02 102519/week @ 2024-08-09 123517/week @ 2024-08-16 108106/week @ 2024-08-23 99994/week @ 2024-08-30 126712/week @ 2024-09-06 115148/week @ 2024-09-13 142701/week @ 2024-09-20 124132/week @ 2024-09-27 162572/week @ 2024-10-04 139311/week @ 2024-10-11 155411/week @ 2024-10-18 184724/week @ 2024-10-25 151503/week @ 2024-11-01 168176/week @ 2024-11-08

690,133 downloads per month
Used in 273 crates (via quote-use)

MIT license

18KB
345 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

~325–770KB
~18K SLoC