Crates.io | quote-use-macros |
lib.rs | quote-use-macros |
version | 0.8.4 |
source | src |
created_at | 2023-09-03 12:49:35.341668 |
updated_at | 2024-08-25 12:48:06.030177 |
description | Support `use` in procmacros hygienically |
homepage | |
repository | https://github.com/ModProg/quote-use |
max_upload_size | |
id | 962229 |
size | 17,662 |
quote!
Macro to simplify using Types in the quote!
macro.
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")
}
This also allows to use contents of the rust prelude directly:
quote_use!{
Some("src/main.rs")
}
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
}
By default quote_use!
uses the std prelude for 2021 edition,
but this can be configured via features, and also completely disabled.
prelude_std
: Enables std::prelude::v1
(incompatible with prelude_core
)prelude_core
: Enables core::prelude::v1
(incompatible with prelude_std
)prelude_2021
: Enables core::prelude::rust_2021
(requires either prelude_std
or prelude_core
)There are also variants for other quote macros from syn and quote:
quote_use!
and quote_spanned_use!
as replacement for quote!
and
quote_spanned!
respectivelyparse_quote_use!
and parse_quote_spanned_use!
for parse_quote!
and parse_quote_spanned!
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}"
.