Rust Formatter
Format and beautify Rust source code online. Fix indentation and normalize Rust syntax.
Input
Output
What is Rust?
Rust is a systems programming language focused on safety, speed, and concurrency. It prevents memory bugs at compile time through its ownership system and is widely used for systems programming, WebAssembly, and high-performance applications.
The Rust Formatter normalizes indentation (4 spaces per level, following rustfmt conventions), fixes brace alignment, and removes trailing whitespace.
How to Use
Paste your Rust code
Paste raw or messy Rust source code into the left editor, or click Upload to load a file.
Instant formatting
The formatter automatically normalizes indentation with 4 spaces per level and fixes brace alignment.
Copy or download
Use the Copy button to copy the result, or Download to save it as a .rs file.
Formatting Example
Example: Format a Rust struct
Unformatted input:
struct User{name:String,age:u32}impl User{fn new(name:String,age:u32)->Self{User{name,age}}
fn greet(&self)->String{format!("Hello, {}!",self.name)}}Formatted output:
struct User {
name: String,
age: u32,
}
impl User {
fn new(name: String, age: u32) -> Self {
User { name, age }
}
fn greet(&self) -> String {
format!("Hello, {}!", self.name)
}
}Frequently Asked Questions
What is rustfmt?
rustfmt is the official Rust code formatter. This tool provides quick online formatting for review purposes. For production use, run rustfmt locally as part of your CI/CD pipeline.
Does Rust use spaces or tabs?
The official Rust style guide uses 4 spaces for indentation, which this formatter follows. See The Rust Book and Rust by Example for more on Rust conventions.
Can I format Rust macros?
The formatter handles basic block indentation. Complex macros may require rustfmt for accurate formatting.
Is my Rust code safe when I use this tool?
Yes, completely. All formatting runs directly in your browser — no code is ever uploaded to a server. Your Rust source stays private and secure at all times.