21 releases

new 0.7.4 Apr 29, 2025
0.7.2 Mar 29, 2025
0.5.10 Dec 15, 2024
0.5.4 Nov 19, 2024
0.5.0 Jul 21, 2024

#817 in Procedural macros

Download history 132/week @ 2025-01-06 147/week @ 2025-01-13 198/week @ 2025-01-20 140/week @ 2025-01-27 295/week @ 2025-02-03 116/week @ 2025-02-10 115/week @ 2025-02-17 198/week @ 2025-02-24 482/week @ 2025-03-03 87/week @ 2025-03-10 37/week @ 2025-03-17 176/week @ 2025-03-24 193/week @ 2025-03-31 110/week @ 2025-04-07 114/week @ 2025-04-14 113/week @ 2025-04-21

569 downloads per month
Used in 26 crates (6 directly)

ISC license

245KB
6K SLoC

This is the library-version of genemichaels, useful for generating code, testing proc macro output (deterministically formatting for string comparisons), the uses are various!

Usage

Do cargo add genemichaels

There are three main functions:

  • genemichaels::format_str - formats a string (full rust source file, doesn't support snippets at the moment).
  • genemichaels::format_ast - formats AST element (implements genemichaels::Formattable, most syn::* structs do). Comments need to be passed in separately, if you have any.
  • genemichaels::extract_comments - takes a string of source code and extracts comments, mapping each comment to the start of a syntax element

If you want to format a TokenStream, parse it into an AST with syn::parse2::<syn::File>(token_stream) then call format_ast.

The format functions also return lost comments - comments not formatted/added to the formatted source after processing. In an ideal world this wouldn't exist, but right now comments are added on a case by case basis and not all source tokens support comments.

Dependencies

~11–22MB
~340K SLoC