Function macro_tools::report_format

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

Formats a debugging report for code transformation processes, detailing both the original and generated code for easy comparison and review.

This function creates a structured report comprising the initial input code, the resulting generated code, and an explanatory context. It is designed to facilitate debugging and documentation of code transformations, such as those performed in procedural macros or similar code generation tasks. The report categorizes the information into labeled sections to enhance readability and traceability.

This function helps visualize the changes from the original to the generated code, assisting developers in verifying and understanding the transformations applied during code generation processes.

§Parameters

  • about : A description or context explaining the purpose or nature of the transformation. This information is displayed at the beginning of the report to provide an overview of the code transformation context.
  • input : The original code before transformation. This is typically the code that is subject to processing by macros or other code generation tools.
  • output : The code generated as a result of the transformation. This reflects the changes or enhancements made to the original code.

§Type Parameters

  • IntoAbout : A type that can be converted into a string representation, providing a descriptive context for the report.
  • IntoInput : A type representing the original code, which can be converted into a string format for display.
  • IntoOutput : A type representing the generated code, which can be converted into a string format for display.

§Returns

A string containing the formatted debug report, organized into sections with appropriate labels and indentation to distinguish between the original and generated code segments.

§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 }
    }
  }
};

// Format the debug report for printing or logging
let formatted_report = report_format( "Code Transformation for MyStruct", original_input, generated_code );
println!( "{}", formatted_report );