20 releases

0.8.0 Nov 16, 2023
0.7.1 May 21, 2023
0.7.0 Mar 31, 2023
0.5.1 Jun 19, 2022

#180 in Procedural macros

Download history 16158/week @ 2023-12-23 32441/week @ 2023-12-30 44143/week @ 2024-01-06 45678/week @ 2024-01-13 43961/week @ 2024-01-20 38720/week @ 2024-01-27 43919/week @ 2024-02-03 43287/week @ 2024-02-10 44670/week @ 2024-02-17 51914/week @ 2024-02-24 53357/week @ 2024-03-02 44069/week @ 2024-03-09 43674/week @ 2024-03-16 51620/week @ 2024-03-23 60700/week @ 2024-03-30 50842/week @ 2024-04-06

214,166 downloads per month
Used in 189 crates (9 directly)

MIT license

13KB
95 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
~20K SLoC