19 releases

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

#1035 in Procedural macros

Download history 471/week @ 2024-12-13 61/week @ 2024-12-20 31/week @ 2024-12-27 116/week @ 2025-01-03 138/week @ 2025-01-10 133/week @ 2025-01-17 215/week @ 2025-01-24 282/week @ 2025-01-31 130/week @ 2025-02-07 108/week @ 2025-02-14 129/week @ 2025-02-21 533/week @ 2025-02-28 129/week @ 2025-03-07 47/week @ 2025-03-14 55/week @ 2025-03-21 252/week @ 2025-03-28

583 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–21MB
~339K SLoC