Rustfmt Rust Code Formatter

Rustfmt Rust Code Formatter

rust-lang.github.io

3

About this website

Rustfmt (rustfmt) is the official code formatting tool for the Rust programming language, providing automatic formatting of Rust source code according to a consistent style guide. Developed by the Rust Style Team and the Rust Dev Tools Team, Rustfmt was first released in 2016 and is maintained as part of the Rust language toolchain. Key features: style guide: formats code according to the official Rust Style Guide, which defines conventions for indentation (4 spaces), line width (default 100 characters, configurable), brace placement, trailing commas, import ordering, and whitespace rules. Automatic formatting: reformats entire files or directories with a single command (cargo fmt or rustfmt), ensuring consistent code style across a project. The formatter is designed to be idempotent: running it multiple times produces the same output. Configuration: over 50 configuration options via rustfmt.toml, including max_width, hard_tabs, tab_spaces, newline_style, use_small_heuristics, import_granularity, group_imports, reorder_imports, reorder_modules, normalize_comments, wrap_comments, format_code_in_doc_comments, and many more. Edition support: respects Rust edition (2015, 2018, 2021) in formatting decisions. Format-on-save: integrates with VS Code, Neovim, IntelliJ Rust, and other IDEs for automatic formatting on file save. Git integration: can format only changed files (cargo fmt --check) for use in CI pipelines, failing the build if code is not properly formatted. Unstable features: nightly-only features (imports_granularity, group_imports, condense_wildcard_suffixes) available with the nightly toolchain. Attribute control: developers can disable formatting for specific code blocks using #![rustfmt::skip] attributes. Rustfmt is used in virtually all Rust projects and is required by the Rust standard library and major Rust ecosystems (Tokio, Serde, Bevy). MPL-2.0 (some components Apache-2.0/MIT).

Tags & Categories

Statistics

3
Views
0
Clicks
0
Like
0
Dislike

Comments

Log In to post a comment

No comments yet. Be the first!