ast2str
A proc macro for pretty-printing ASTs and other recursive data structures.
Basic Usage
Refer to the snippet below for a basic usage example, and see the integration test and these two repos (#1.1 + #1.2, #2.1) for larger samples.
// Import the macro
use AstToStr;
type Span = Range;
// Annotate some structs and enums as desired
let expr = Binary ;
assert_eq!;
// The symbols used to draw the tree can be configured using the [`Symbols`] trait:
assert_eq!;
Available Attributes
Attribute | |
---|---|
None | Format the value with [AstToStr ] |
#[forward] |
Skip all other fields and return the [AstToStr ] of the annotated field |
#[skip] |
Skip the annotated field |
#[display] |
Format the annotated field with [Display ] instead of [AstToStr ] |
#[debug] |
Format the annotated field with [Debug ] instead of [AstToStr ] |
#[quoted] |
Like #[display] but also wraps the value with backticks |
#[list] |
Format the annotated field by executing AstToStr on every element of (&field).into_iter() |
#[list(name_or_closure) |
Format the annotated field by applying the callback on every element of (&field).into_iter() |
#[callback(name_or_closure)] |
Apply the given function or closure to &field and return the result |
#[delegate = "getter"] |
Call self.getter() and format the result as a field |
#[default = "value"] |
Only applies to Option types. If the value is Some(T) , format &T with AstToStr. Otherwise, return the value of default |
#[skip_if = "my_condition_fn"] |
Skip the annotated field if the specified function returns true |