Rust Code Formatter
Reformat Rust source code with rustfmt-style conventions — 4-space indentation, brace-on-same-line, and normalized comma/colon spacing — entirely in your browser.
🔒 This tool runs entirely in your browser. Your files are never uploaded to a server.
Example shown. Applies rustfmt-style conventions: 4-space indent, brace-on-same-line, space after commas/colons — not a full parser, so unusual macro syntax may not reformat perfectly.
How the Rust Code Formatter works
- Paste any Rust source snippet into the input box.
- Click Format code to re-indent it using 4-space steps tracked by brace/paren/bracket depth.
- Spacing around commas and colons is normalized, and opening braces are pulled onto the same line as their statement, matching rustfmt's default style.
What it doesn't do
This is a lightweight, browser-only approximation. It doesn't parse Rust syntax into a real AST, so it can't reflow long lines at the 100-character limit or reorder use statements the way the official rustfmt does — it's meant for quick cleanup, not a CI gate.
FAQ
Does this replace rustfmt?
No. This applies common rustfmt-style conventions — 4-space indentation, brace-on-same-line, consistent spacing after commas and colons — using text-based rules, not the real Rust compiler front-end. For CI pipelines and production code, run the actual rustfmt.
Will it handle complex macros and lifetimes correctly?
Basic syntax formats reliably, but unusual macro invocations, raw strings, and deeply nested generic lifetime bounds may not indent exactly as the real rustfmt would, since this tool works on braces and tokens rather than a full Rust AST.
Is my code uploaded anywhere?
No. Formatting happens entirely in your browser with plain JavaScript string processing — nothing is sent to a server.
How we compare
| Feature | Online Tool Store | rustfmt (cargo) | Manual formatting |
|---|---|---|---|
| No install required | ✓ | ✗ | ✓ |
| Real AST-based formatting | ✗ | ✓ | ✗ |
Use this for a quick tidy-up when you don't have a Rust toolchain handy; use `cargo fmt` for anything going into a real project.