Function macro_tools::report_print

source ·
pub fn report_print<IntoAbout, IntoInput, IntoOutput>(
    about: IntoAbout,
    input: IntoInput,
    output: IntoOutput
)
where IntoAbout: ToString, IntoInput: ToString, IntoOutput: ToString,
Expand description

Prints a debugging report for a pair of token streams to the standard output.

This function acts as a utility for debugging transformations in procedural macros or other code generation scenarios. It provides an immediate visual comparison of the original code versus the generated code by utilizing the report_format function to format the output and then printing it directly to the standard output. This can be particularly helpful for real-time debugging and quick assessments without requiring additional output management.

§Parameters and Type Parameters

  • about : A description of the code transformation context or operation. This is used to headline the generated report.
  • input : The original code or token stream before transformation. This is what the code looked like prior to any procedural manipulations.
  • output : The transformed or generated code or token stream as a result of the macro or code transformation process.

The types for these parameters are expected to be convertible to strings, matching the report_format function’s requirements.

§Examples

use macro_tools::exposed::*;

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

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

// Directly print the debug report
report_print( "Code Transformation for MyStruct", original_input, generated_code );

The above example demonstrates how the report_print function can be used to visualize the changes from original input code to the generated code, helping developers to verify and understand the modifications made during code generation processes. The output is formatted to show clear distinctions between the ‘original’ and ‘generated’ sections, providing an easy-to-follow comparison.