Expand description

Tools for writing procedural macroses.

Module :: macro_tools

experimental rust-status docs.rs discord

Tools for writing procedural macroses.

Sample

use macro_tools::*;
use macro_tools::dependencies::*;
use quote::quote;

fn main()
{
  let code = quote!( 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!( "{}", quote!( #e ) ) );
  // < i8
  // < i16
  // < i32
}

To add to your project

cargo add macro_tools

Modules

Dependencies of the module.

Exposed namespace of the module.

Helpers.

Trait name.

Prelude to use: use wtools::prelude::*.

Split with name.

Macros

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 string.

Macro for diagnostics purpose to print both syntax tree and source code behind it.

Quasi-quotation macro that accepts input like the quote! macro but uses type inference to figure out a return type for those tokens.

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 string.

Macro for diagnostics purpose to print both syntax tree and source code behind it.

Structs

Many items.

Enums

Kind of container.

Traits

Trait to get name of an syntax element.

Functions

For attribute like #[former( default = 31 )] return key default and value 31, as well as syn::Meta as the last element of result tuple.

Return kind of container specified by type.

Return kind of container specified by type. Unlike type_container_kind it also understand optional types.

Return the specified number of parameters of the type.

Check is the rightmost item of path refering a type is specified type.

Type Definitions

Result with syn::Error.