Crate quote_use

source ·
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 using 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 core prelude, std prelude and 2021 edition prelude. Preferring core where available.

All preludes can be disabled by adding # use no_prelude; at the top of the macro input. The std prelude can be disabled with # use no_std_prelude;.

§Other quote macros

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

Macros§

Traits§

  • Specialized formatting trait used by format_ident!.
  • Types that can be interpolated inside a quote! invocation.
  • TokenStream extension trait with methods for appending tokens.