Expand description
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, core prelude and 2021 edition prelude,
but this can be configured via features, and also completely disabled.
prelude_core: Enablescore::prelude::v1prelude_std: Enablesstd::prelude::v1(Adds only those missing in core and enables alsoprelude_core)prelude_2021: Enablescore::prelude::rust_2021(enables alsoprelude_core)
Other quote macros
There are also variants for other quote macros from syn and quote:
quote_use!andquote_spanned_use!as replacement forquote!andquote_spanned!respectivelyparse_quote_use!andparse_quote_spanned_use!forparse_quote!andparse_quote_spanned!
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}".
Macros
format_ident!replacement that allows the auto namespacing matching thequote!macros of this crate.- Like
quote_spanned_use!but usingparse_quote_spanned! - Like
quote_use!but usingparse_quote! - Like
quote_use!but usingquote_spanned!