Crate proc_macro_tools

Source
Expand description

Tools for writing procedural macroses.

§Module :: proc_macro_tools

experimental rust-status docs.rs Open in Gitpod discord

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
githubcrates-iodocs-rs
protected
Protected namespace of the module.
quantifier
Quantifiers like Pair and Many.
quote
githubcrates-iodocs-rs
syn
githubcrates-iodocs-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§

AttributesInner
Attribute which is inner.
AttributesOuter
Attribute which is outer.
EnumerableIteratorConsumable
Iterator for enumerable.
EnumerableIteratorNonConsumable
Iterator for enumerable.
GenericsAnalysis
Result of generics analyze.
HomoPair
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§

ContainerKind
Kind of container.

Traits§

AsArray
Reinterpret as array.
AsMuchAsPossibleNoDelimiter
Marker saying how to parse several elements of such type in a row.
AsSlice
Reinterpret as slice.
AsTuple
Reinterpret as tuple.
CloneAsArray
Clone as array.
CloneAsTuple
Clone as tuple.
Enumerable
Has length and indexed access.
GenericsAnalyze
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.
VectorizedFrom
Implementation of trait From to vectorize into/from.
VectorizedInto
Implementation of trait Into to vectorize into/from.

Functions§

attr_pair_single
For attribute like #[former( default = 31 )] return key default and value 31, 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§

AttributedIdent
Attribute and ident.
ParseStream
Input to a Syn parser function.
Result
Result with syn::Error.