quote-use-0.8.4/.cargo_vcs_info.json0000644000000001360000000000100127740ustar { "git": { "sha1": "05096f346f8b17fba8a57a235b958917ad9d99e0" }, "path_in_vcs": "" }quote-use-0.8.4/Cargo.toml0000644000000036540000000000100110020ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" name = "quote-use" version = "0.8.4" build = false include = [ "src/**/*", "LICENSE", "README.md", ] autobins = false autoexamples = false autotests = false autobenches = false description = "Support `use` in procmacros hygienically" documentation = "https://docs.rs/quote-use" readme = "README.md" keywords = ["macro"] categories = [ "rust-patterns", "development-tools::procedural-macro-helpers", "parsing", ] license = "MIT" repository = "https://github.com/ModProg/quote-use" [package.metadata.docs.rs] all-features = true [package.metadata.release] shared-version = true [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" replace = """ ## [{{version}}] - {{date}}""" search = '## \[Unreleased\]' [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" replace = """ [unreleased]: $1/{{tag_name}}...HEAD [{{version}}]: $1/$2...{{tag_name}}""" search = '\[unreleased\]: (.*)/(v.*)\.\.\.HEAD' [lib] name = "quote_use" path = "src/lib.rs" [dependencies.quote] version = "1" [dependencies.quote-use-macros] version = "0.8.4" [dependencies.syn] version = "2" features = [ "parsing", "printing", ] optional = true default-features = false [dev-dependencies.pretty_assertions] version = "1" [dev-dependencies.proc-macro2] version = "1.0.60" [dev-dependencies.syn] version = "2" features = ["derive"] [dev-dependencies.trybuild2] version = "1.2.0" [features] quote-use-0.8.4/Cargo.toml.orig000064400000000000000000000023661046102023000144620ustar 00000000000000[workspace] [package] categories = [ "rust-patterns", "development-tools::procedural-macro-helpers", "parsing", ] description = "Support `use` in procmacros hygienically" documentation = "https://docs.rs/quote-use" include = ["src/**/*", "LICENSE", "README.md"] keywords = ["macro"] license = "MIT" readme = "README.md" repository = "https://github.com/ModProg/quote-use" version = "0.8.4" edition = "2021" name = "quote-use" [dependencies] syn = { version = "2", default-features = false, features = ["parsing", "printing"], optional = true } quote = "1" quote-use-macros = { version = "0.8.4", path = "quote-use-macros" } [features] [dev-dependencies] pretty_assertions = "1" proc-macro2 = "1.0.60" syn = { version = "2", features = ["derive"] } trybuild2 = "1.2.0" [package.metadata.docs.rs] all-features = true [package.metadata.release] shared-version = true [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = '## \[Unreleased\]' replace = """ ## [{{version}}] - {{date}}\ """ [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = '\[unreleased\]: (.*)/(v.*)\.\.\.HEAD' replace = """ [unreleased]: $1/{{tag_name}}...HEAD [{{version}}]: $1/$2...{{tag_name}}\ """ quote-use-0.8.4/README.md000064400000000000000000000067011046102023000130470ustar 00000000000000# Use statements in `quote!` [![Crates.io Version](https://img.shields.io/crates/v/quote-use.svg)](https://crates.io/crates/quote-use) [![CI](https://github.com/ModProg/quote-use/actions/workflows/test.yml/badge.svg)](https://github.com/ModProg/quote-use/actions/workflows/test.yml) [![Docs.rs Documentation](https://img.shields.io/docsrs/quote-use)](https://docs.rs/crate/quote-use) ## Description Macro to simplify using Types in the [`quote!`](https://docs.rs/quote/latest/quote/macro.quote.html) macro. ## Usage The [`quote_use!`](https://docs.rs/quote-use/latest/quote_use/macro.quote_use.html) macro can be used just like [`quote!`](https://docs.rs/quote/latest/quote/macro.quote.html), but with the added functionality of adding use statements at the top: ```rust quote_use!{ use std::fs::read; read("src/main.rs") } ``` This will expand to the equivalent statement using [`quote!`](https://docs.rs/quote/latest/quote/macro.quote.html): ```rust quote!{ ::std::fs::read::read("src/main.rs") } ``` ### Prelude This also allows to use contents of the rust prelude directly: ```rust 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 ```rust quote_use!{ use anyhow::Result; Result } ``` #### Different preludes By default [`quote_use!`](https://docs.rs/quote-use/latest/quote_use/macro.quote_use.html) uses the [std prelude](std::prelude) for [2021 edition](std::prelude::rust_2021), but this can be configured via features, and also completely disabled. - **`prelude_std`**: Enables [`std::prelude::v1`](https://doc.rust-lang.org/nightly/std/prelude/v1/index.html) (incompatible with `prelude_core`) - `prelude_core`: Enables [`core::prelude::v1`](https://doc.rust-lang.org/nightly/core/prelude/v1/index.html) (incompatible with `prelude_std`) - **`prelude_2021`**: Enables [`core::prelude::rust_2021`](https://doc.rust-lang.org/nightly/core/prelude/rust_2021/index.html) (requires either `prelude_std` or `prelude_core`) ### Other quote macros There are also variants for other quote macros from [syn](https://docs.rs/syn/latest/syn/) and [quote](https://docs.rs/quote/latest/quote/): - [`quote_use!`](https://docs.rs/quote-use/latest/quote_use/macro.quote_use.html) and [`quote_spanned_use!`](https://docs.rs/quote-use/latest/quote_use/macro.quote_spanned_use.html) as replacement for [`quote!`](https://docs.rs/quote/latest/quote/macro.quote.html) and [`quote_spanned!`](https://docs.rs/quote/latest/quote/macro.quote_spanned.html) respectively - [`parse_quote_use!`](https://docs.rs/quote-use/latest/quote_use/macro.parse_quote_use.html) and [`parse_quote_spanned_use!`](https://docs.rs/quote-use/latest/quote_use/macro.parse_quote_spanned_use.html) for [`parse_quote!`](https://docs.rs/syn/latest/syn/macro.parse_quote.html) and [`parse_quote_spanned!`](https://docs.rs/syn/latest/syn/macro.parse_quote_spanned.html) ## Auto namespacing idents Until [`Span::def_site`](https://doc.rust-lang.org/stable/proc_macro/struct.Span.html#method.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}"`. quote-use-0.8.4/src/lib.rs000064400000000000000000000075101046102023000134720ustar 00000000000000//! # 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: //! //! ``` //! # use quote_use::quote_use; //! quote_use! { //! ## use std::fs::read; //! //! read("src/main.rs") //! } //! # ; //! ``` //! //! This will expand to the equivalent statement using [`quote!`]: //! //! ``` //! # use quote::quote; //! quote! { //! ::std::fs::read::read("src/main.rs") //! } //! # ; //! ``` //! //! ## Prelude //! //! This also allows using contents of the rust prelude directly: //! //! ``` //! # use quote_use::quote_use; //! 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 //! //! ``` //! # use quote_use::quote_use; //! quote_use! { //! ## use anyhow::Result; //! //! Result //! } //! # ; //! ``` //! ### Different preludes //! //! By default [`quote_use!`] uses the [core prelude](core::prelude), [std //! prelude](std::prelude) and [2021 edition prelude](std::prelude::rust_2021). //! 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 [mod@quote]: //! //! - [`quote_use!`] and [`quote_spanned_use!`] as replacement for [`quote!`] //! and //! [`quote_spanned!`](quote::quote_spanned!) respectively //! - [`parse_quote_use!`] and [`parse_quote_spanned_use!`] for //! [`parse_quote!`](syn::parse_quote!) //! and [`parse_quote_spanned!`](syn::parse_quote_spanned!) #[cfg(doc)] use quote::quote; // Reexport pub use quote::{format_ident, IdentFragment, ToTokens, TokenStreamExt}; #[doc(hidden)] pub mod __private { pub use quote; pub use quote_use_macros::quote_use_impl; #[cfg(feature = "syn")] pub use syn; } #[macro_export] macro_rules! quote_use { ($($tokens:tt)*) => { $crate::__private::quote_use_impl!{($crate::__private::quote::quote) () ($($tokens)*)} }; } #[macro_export] macro_rules! quote_spanned_use { ($span:expr => $($tokens:tt)*) => { $crate::__private::quote_use_impl!{($crate::__private::quote::quote_spanned) ($span =>) ($($tokens)*)} }; } #[cfg(feature = "syn")] #[macro_export] macro_rules! parse_quote_use { ($($tokens:tt)*) => { $crate::__private::quote_use_impl!{($crate::__private::syn::parse_quote) () ($($tokens)*)} }; } #[cfg(feature = "syn")] #[macro_export] macro_rules! parse_quote_spanned_use { ($span:expr => $($tokens:tt)*) => { $crate::__private::quote_use_impl!{($crate::__private::syn::parse_quote_spanned) ($span =>) ($($tokens)*)} }; } #[macro_export] macro_rules! quote_use_no_prelude { ($($tokens:tt)*) => { $crate::__private::quote_use_impl!{($crate::__private::quote::quote) () (#use no_prelude; $($tokens)*)} }; } #[macro_export] macro_rules! quote_spanned_use_no_prelude { ($span:expr => $($tokens:tt)*) => { $crate::__private::quote_use_impl!{($crate::__private::quote::quote_spanned) ($span =>) (#use no_prelude; $($tokens)*)} }; } #[cfg(feature = "syn")] #[macro_export] macro_rules! parse_quote_use_no_prelude { ($($tokens:tt)*) => { $crate::__private::quote_use_impl!{($crate::__private::syn::parse_quote) () (#use no_prelude; $($tokens)*)} }; } #[cfg(feature = "syn")] #[macro_export] macro_rules! parse_quote_spanned_use_no_prelude { ($span:expr => $($tokens:tt)*) => { $crate::__private::quote_use_impl!{($crate::__private::syn::parse_quote_spanned) ($span =>) (#use no_prelude; $($tokens)*)} }; }