29 releases

new 0.8.5 Dec 26, 2025
0.8.2 Nov 28, 2025
0.7.5 May 28, 2025
0.7.2 Mar 29, 2025
0.5.0 Jul 21, 2024

#545 in Procedural macros

Download history 413/week @ 2025-09-11 361/week @ 2025-09-18 248/week @ 2025-09-25 288/week @ 2025-10-02 185/week @ 2025-10-09 230/week @ 2025-10-16 334/week @ 2025-10-23 163/week @ 2025-10-30 188/week @ 2025-11-06 216/week @ 2025-11-13 199/week @ 2025-11-20 263/week @ 2025-11-27 234/week @ 2025-12-04 170/week @ 2025-12-11

466 downloads per month
Used in 27 crates (6 directly)

ISC license

260KB
6.5K 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

~10–26MB
~349K SLoC