Crate macro_tools
source ·Expand description
§Module :: proc_macro_tools
Tools for writing procedural macros.
§Basic use-case
#[ cfg( feature = "enabled" ) ]
{
use macro_tools::exposed::*;
let code = qt!( core::option::Option< i8, i16, i32, i64 > );
let tree_type = syn::parse2::< syn::Type >( code ).unwrap();
let got = typ::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 examples/macro_tools_trivial
cargo run
Modules§
- Protected namespace of the module.
- Protected namespace of the module.
- Dependencies of the module.
- Protected namespace of the module.
- Protected namespace of the module.
- Protected namespace of the module.
- Exposed namespace of the module.
- Protected namespace of the module.
- Functions and structures to handle and manipulate generic parameters using the
syn
crate. It’s designed to support macro-driven code generation by simplifying, merging, extracting, and decomposingsyn::Generics
. - This module provides various utilities and namespaces for working with
syn::Item
, specifically focusing on ensuring syntactical correctness and managing different visibility levels within the code. It includes functions to manipulate the structure of items, handle different kinds of fields, and provide a structured approach to organizing the codebase into different access levels. - Protected namespace of the module.
- Protected namespace of the module.
- Protected namespace of the module.
- Parented namespace of the module.
- Responsible for generating marker
PhantomData
fields to avoid the rule requiring the usage of all generic parameters in a struct. This is often necessary to ensure that Rust’s type system correctly tracks the ownership and lifetimes of these parameters without needing them to be explicitly used in the struct’s fields. - Prelude to use essentials:
use my_module::prelude::*
. - Protected namespace of the module.
- Structures and functions for handling
syn::punctuated::Punctuated
collections. - Protected namespace of the module.
- Protected namespace of the module.
- Protected namespace of the module.
- Protected namespace of the module.
Macros§
- A type-macro that expands to the name of the Rust type representation of a given token.
- Parse a set of curly braces and expose their content to subsequent parsers.
- Parse a set of square brackets and expose their content to subsequent parsers.
- Macro for diagnostics purpose to diagnose source code behind it and export it into a string.
- Macro for diagnostics purpose to print both syntax tree and source code behind it without syntax tree.
- Macro to export source code behind a syntax tree into a string.
- Define a type that supports parsing and printing a given identifier as if it were a keyword.
- Define a type that supports parsing and printing a multi-character symbol as if it were a punctuation token.
- Formatting macro for constructing
Ident
s. - Parse a set of parentheses and expose their content to subsequent parsers.
- Parse the input TokenStream of a macro, triggering a compile error if the tokens fail to parse.
- Quasi-quotation macro that accepts input like the
quote!
macro but uses type inference to figure out a return type for those tokens. - Quasi-quotation macro that accepts input like the
quote!
macro but uses type inference to figure out a return type for those tokens. - This macro is
parse_quote!
+quote_spanned!
. - Macro to generate syn error either with span of a syntax tree element or with default one
proc_macro2::Span::call_site()
. - Macro to generate syn error either with span of a syntax tree element or with default one
proc_macro2::Span::call_site()
. - Macro for diagnostics purpose to export both syntax tree and source code behind it into a string.
- Macro for diagnostics purpose to print both syntax tree and source code behind it with syntax tree.
Structs§
- Attribute which is inner.
- Represents a collection of outer attributes.
- Represents an equation parsed from a procedural macro input.
- A
GenericsWithWhere
struct to handle the parsing of Rust generics with an explicitwhere
clause. - Parse as much elements as possible.
- Pair of two elements of parsing.
Tokens
is a wrapper aroundproc_macro2::TokenStream
. It is designed to facilitate the parsing and manipulation of token streams within procedural macros.
Traits§
- Marker saying how to parse several elements of such type in a row.
- A trait for converting a reference to an existing type into a
syn::AngleBracketedGenericArguments
. - Convert it into canonical interval.
- Trait that encapsulates an iterator with specific characteristics, tailored for use with the
syn
crate. - Interval adapter. Interface to interval-like structures.
- Trait to get name of an syntax element.
- Interval adapter. Interface to interval-like structures.
- A trait that can provide the
Span
of the complete contents of a syntax tree node.
Functions§
- For attribute like
#[former( default = 31 ) ]
return keydefault
and value31
, as well as syn::Meta as the last element of result tuple. - Checks if the given iterator of attributes contains an attribute named
debug
. - Adds indentation and optional prefix/postfix to each line of the given string.
- Checks if the given attribute name is a standard Rust attribute.
- Formats a debugging report for code transformation processes, detailing both the original and generated code for easy comparison and review.
- Prints a debugging report for a pair of token streams to the standard output.
Type Aliases§
- Input to a Syn parser function.
- Result with syn::Error.