| Crates.io | genemichaels-lib |
| lib.rs | genemichaels-lib |
| version | 0.8.5 |
| created_at | 2024-07-21 16:09:09.052789+00 |
| updated_at | 2025-12-26 18:51:55.435294+00 |
| description | Makes your code formatty, the library |
| homepage | |
| repository | https://github.com/andrewbaxter/genemichaels |
| max_upload_size | |
| id | 1310417 |
| size | 297,029 |
This is the library-version of genemichaels, useful for generating code, testing proc macro output (deterministically formatting for string comparisons), the uses are various!
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 elementIf 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.