Home » Developer Tools » Rust Formatter
Paste Rust code and get clean, readable formatting in seconds, right in your browser.
Last updated 13 November 2026
This formatter changes whitespace only. It never compiles, runs, validates, adds, removes, or renames code tokens.
Messy Rust code with collapsed indentation is hard to read, review and debug. The Rust Formatter fixes indentation, line breaks and spacing so your code is easy to follow again.
Everything runs in your browser, so your code is never uploaded to a server. Paste your code, format it, and copy the result straight into your project.
Rust is a systems language used for fast and safe programs, from command line tools to web services. A Rust formatter takes Rust code that is hard to read and lays it out again with clean indentation, line breaks and spacing. It changes whitespace only, so the code still does exactly what it did before, only now a person can follow it. This page is a formatter, not a compiler, so it never checks whether your code is correct.
You paste code into the input box, pick 2 or 4 spaces per level, press Format, and copy the result or download it as a .rs file. Everything runs in your browser, so your code never leaves your device, there is nothing to install, and no account is needed. If you work in more than one language, the same clean layout is available for Go code with the Go Formatter, for Java code with the Java Formatter, and for Python code with the Python Formatter.
Here is a short program run through the tool, with the exact numbers. Input, 71 characters:
use foo::*; fn main() { let m: HashMap<String, i32> = HashMap::new(); }
Output, 75 characters, 4 lines:
use foo::*;
fn main() {
let m: HashMap<String, i32> = HashMap::new();
}
The output is 4 characters longer than the input because the indent spaces are added back. That is the point: the extra characters are the structure made visible. Notice three details. The glob import use foo::*; stays exactly as written, with the star glued to the path. The generic type HashMap<String, i32> stays on one line. And the indent inside fn main() is 4 spaces, the rustfmt default.
The Load Sample button shows the same effect on a bigger file. Its 206 character sample, a greet function plus a match on a score, formats to 266 characters and 14 lines, with the macro call format! written tight and the match arms each on their own line.
rustfmt is the official Rust formatter, and cargo fmt runs it across a whole project. This page is not rustfmt. It is a whitespace only formatter that runs in your browser with no install, and it is honest about that limit.
Use this page when you need to read a snippet quickly, for example code pasted from a chat message or a forum answer. Use cargo fmt when you need to format a whole project, because it also wraps long lines, aligns code to the project style, and reads your rustfmt.toml settings. This tool does none of those things, and it never claims to.
The difference matters most for production code. Format a snippet here to read it, then run cargo fmt on the project itself before you commit. That way you get a quick read now and the official style where it counts.
The formatter follows a small set of rules, and it applies them the same way every time. Knowing the rules helps you predict the output before you press Format.
| Rule | What it means |
|---|---|
| One statement per line | Each statement ends on its own line, so you can read the code from top to bottom |
| Braces on the same line | An opening brace stays on the same line as the declaration, and the closing brace gets its own line |
| Indent 2 or 4 spaces | Each level inside a block moves right by the indent size you pick |
| Glob imports kept intact | A glob import such as use foo::*; keeps its star glued to the path |
| Generics kept together | A generic type such as HashMap<String, i32> stays on one line, even when it is nested inside another generic type |
| Macros kept tight | A macro call such as format! keeps the ! glued to the macro name |
| Lifetimes and match arms | Lifetimes stay with their types and are never mistaken for character literals, and match arms sit on their own lines |
| Strings and comments untouched | Text inside quotes and comments is copied exactly, even when it looks like code |
This tool is deliberately narrow, and it is honest about its limits. It never compiles, runs or validates your code, so it cannot tell you whether your code is correct. It does not wrap long lines and it has no max line length setting, so a long line stays on one line. It does not align struct fields, it does not offer tabs or 8 spaces, and it does not add line numbers or syntax highlighting. There is no file upload, so paste your code into the input box, and there is no format as you type, so press Format when you are ready. There is also no diff view to compare the input with the output side by side. If you need any of those, use rustfmt in your own project. Use this tool for the quick job: take messy code and make it readable in seconds.
Formatting is most useful when Rust code arrives in a shape you cannot read. Code copied from a chat message or a forum answer often arrives on one line or with collapsed indentation, and the first step in understanding it is to expand it into readable lines. The same goes for code pasted from a log file.
It also helps in code review. A clean layout shows the real structure, while a single line hides it. Format the snippet first, read it, then run cargo fmt on the project itself before you commit.
If you work with C code too, the C Formatter gives the same clean layout, and the C# Formatter does the same for C# code.
Yes, it is completely free with no sign up.
No. It changes whitespace only, meaning indentation, line breaks and spacing. It never adds, removes, renames or reorders code tokens, and it never compiles or runs your code.
No. Text inside string literals, character literals and comments is left untouched, even when it looks like code.
No. It never compiles, runs or validates code, so it cannot tell you whether your code is correct. It only makes the layout readable.
No. All formatting happens in your browser on your own device, so your code never leaves your computer.
Lifetimes such as 'a are kept with their types and never mistaken for character literals, and match arms are placed on their own lines.
No. This tool is a whitespace only formatter that runs in your browser. rustfmt is the official Rust formatter, and cargo fmt runs it across a whole project. This tool never wraps long lines, never reads rustfmt.toml settings, and never validates your code. Use this page for a quick read of a snippet, and run cargo fmt on the project itself for production code.
No. There is no file upload on this page. Paste your code into the input box and press Format. You can download the result as a .rs file for your project.
No. A long line stays on one line. There is no max line length setting and no line wrapping. If you need wrapping, run rustfmt on the code in your own project.
Yes. A macro call such as format! stays glued to its name, a glob import such as use foo::*; keeps its star on the path, and a generic type such as HashMap
If you also work with other languages, try the Go Formatter for the same clean formatting.