pub fn debug_report_format<IntoAbout, IntoTokens>(
    about: IntoAbout,
    input: IntoTokens,
    output: &TokenStream
) -> String
where IntoAbout: Into<String>, IntoTokens: Into<TokenStream>,
Expand description

Formats a debugging report for a pair of token streams, showing the original and generated code.

This function takes two inputs: the original code as an IntoTokens (which can be converted into a proc_macro2::TokenStream), and the generated code as a proc_macro2::TokenStream. It formats both inputs with indentation for better readability, labeling them as “original” and “generated” respectively.

Ensure the correct conversion of proc_macro::TokenStream to proc_macro2::TokenStream where necessary, especially when interfacing with procedural macros’ input parameter

§Parameters

  • input: The original input code that can be converted into a proc_macro2::TokenStream.
  • output: The generated code as a proc_macro2::TokenStream.

§Returns

A String containing the formatted debug report.

§Type Parameters

  • IntoTokens: A type that can be converted into a proc_macro2::TokenStream.

§Examples

use macro_tools::exposed::*;

let original_input : proc_macro2::TokenStream = qt!
{
  #[ derive( Debug, PartialEq ) ]
  pub struct MyStruct
  {
    pub field : i32,
  }
};

let generated_code : proc_macro2::TokenStream = qt!
{
  impl MyStruct
  {
    pub fn new( field : i32 ) -> Self
    {
      MyStruct { field }
    }
  }
};

// Format the debug report for printing or logging
let formatted_report = debug_report_format( "derive :: MyDerive", original_input, &generated_code );
println!( "{}", formatted_report );

This will output a formatted report showing the original input code and the generated code side by side, each line indented for clarity.