Expand description
Tools for writing procedural macroses.
§Module :: proc_macro_tools
Tools for writing procedural macroses.
§Sample
#[ cfg( feature = "use_std" ) ]
{
use proc_macro_tools::*;
let code = qt!( core::option::Option< i8, i16, i32, i64 > );
let tree_type = syn::parse2::< syn::Type >( code ).unwrap();
let got = type_parameters( &tree_type, 0..=2 );
got.iter().for_each( | e | println!( "{}", qt!( #e ) ) );
/* print :
i8
i16
i32
*/
}
§To add to your project
cargo add proc_macro_tools
§Try out from the repository
git clone https://github.com/Wandalen/wTools
cd wTools
cd sample/rust/proc_macro_tools_trivial
cargo run
Modules§
- container_
kind - Determine kind of a container.
- dependency
- Dependencies of the module.
- exposed
- Exposed namespace of the module.
- generic_
analyze - Analyze generic to provide more information than trivial syntax node.
- helper
- Macro helpers.
- name
- Tait to getn name of an Item.
- orphan
- Parented namespace of the module.
- parse_
macro_ input - parse_
qt - parse_
quote - prelude
- Prelude to use essentials:
use my_module::prelude::*
. - proc_
macro2 - github crates-io docs-rs
- protected
- Protected namespace of the module.
- quantifier
- Quantifiers like Pair and Many.
- quote
- github crates-io docs-rs
- syn
- github crates-io docs-rs
- syntax
- Advanced syntax elements.
Macros§
- Token
- A type-macro that expands to the name of the Rust type representation of a given token.
- _if_
make - Generate code only if feature::make is enabled.
- braced
- Parse a set of curly braces and expose their content to subsequent parsers.
- bracketed
- Parse a set of square brackets and expose their content to subsequent parsers.
- code_
diagnostics_ str - Macro for diagnostics purpose to diagnose source code behind it and export it into a string.
- code_
export_ str - Macro to export source code behind a syntax tree into a string.
- code_
print - Macro for diagnostics purpose to print both syntax tree and source code behind it without syntax tree.
- custom_
keyword - Define a type that supports parsing and printing a given identifier as if it were a keyword.
- custom_
punctuation - Define a type that supports parsing and printing a multi-character symbol as if it were a punctuation token.
- make
- Variadic constructor.
- parenthesized
- Parse a set of parentheses and expose their content to subsequent parsers.
- parse_
macro_ input - Parse the input TokenStream of a macro, triggering a compile error if the tokens fail to parse.
- parse_
qt - Quasi-quotation macro that accepts input like the
quote!
macro but uses type inference to figure out a return type for those tokens. - parse_
quote - Quasi-quotation macro that accepts input like the
quote!
macro but uses type inference to figure out a return type for those tokens. - parse_
quote_ spanned - This macro is
parse_quote!
+quote_spanned!
. - qt
- The whole point.
- syn_err
- Macro to generate syn error either with span of a syntax tree element or with default one
proc_macro2::Span::call_site()
. - tree_
diagnostics_ str - Macro for diagnostics purpose to export both syntax tree and source code behind it into a string.
- tree_
print - Macro for diagnostics purpose to print both syntax tree and source code behind it with syntax tree.
- types
- Type constructor to define tuple wrapping a given type.
Structs§
- Attributes
Inner - Attribute which is inner.
- Attributes
Outer - Attribute which is outer.
- Enumerable
Iterator Consumable - Iterator for enumerable.
- Enumerable
Iterator NonConsumable - Iterator for enumerable.
- Generics
Analysis - Result of generics analyze.
- Homo
Pair - Type constructor to wrap pair of the same type.
- Many
- Parse as much elements as possible.
- Pair
- Parse as much elements as possible.
- Single
- Type constructor to wrap a another type into a tuple.
Enums§
- Container
Kind - Kind of container.
Traits§
- AsArray
- Reinterpret as array.
- AsMuch
AsPossible NoDelimiter - Marker saying how to parse several elements of such type in a row.
- AsSlice
- Reinterpret as slice.
- AsTuple
- Reinterpret as tuple.
- Clone
AsArray - Clone as array.
- Clone
AsTuple - Clone as tuple.
- Enumerable
- Has length and indexed access.
- Generics
Analyze - To analyze generics.
- Make0
- Constructor without arguments.
- Make1
- Constructor with single argument.
- Make2
- Constructor with two arguments.
- Make3
- Constructor with three arguments.
- Name
- Trait to get name of an syntax element.
- Vectorized
From - Implementation of trait From to vectorize into/from.
- Vectorized
Into - Implementation of trait Into to vectorize into/from.
Functions§
- attr_
pair_ single - For attribute like
#[former( default = 31 )]
return keydefault
and value31
, as well as syn::Meta as the last element of result tuple. - type_
container_ kind - Return kind of container specified by type.
- type_
optional_ container_ kind - Return kind of container specified by type. Unlike type_container_kind it also understand optional types.
- type_
parameters - Return the specified number of parameters of the type.
- type_
rightmost - Check is the rightmost item of path refering a type is specified type.
Type Aliases§
- Attributed
Ident - Attribute and ident.
- Parse
Stream - Input to a Syn parser function.
- Result
- Result with syn::Error.