Rust Code Formatter: Re-indent Blocks (No rustfmt)

Fixes indentation, blank lines and optionally line breaks in Rust code without sending it anywhere.

Use the tool

Why this tool exists

Messy indentation hides the structure of Rust code, and minified or copy-pasted code is worse. A re-indenter gives you the block layout back quickly.

The tool reads your code with a small scanner that knows strings, comments and raw literals, so braces inside them are ignored. It then sets the indent from bracket depth and, if you ask, puts a line break after braces and semicolons. It is not rustfmt.

How to use it

  1. Paste Rust code.
  2. Pick the indent and line break mode.
  3. Copy the result.
  4. Run cargo fmt locally for the official layout.

Frequently asked questions

Is this the same as rustfmt?

No. rustfmt also wraps lines, reorders imports and chooses a layout for chains and arguments. This tool re-indents blocks and where clauses and optionally breaks lines. Re-indenting rustfmt output with its indentation stripped restored 107 of 127 test files exactly.

Will it change what my code does?

It only changes whitespace outside strings, comments and raw literals. Test results: the non-whitespace text was unchanged on all test files, and re-running the tool gave the same output. Review the diff anyway.

Why not wrap long lines?

Wrapping needs a full parser. This tool does not have one.

Is my input sent anywhere?

No. Everything runs in your browser and nothing is uploaded.