← 返回命令列表

Linux command

cargo-fmt 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Format current package

cargo fmt

Format all packages in workspace

cargo fmt --all

Check formatting without changes

cargo fmt --check

Format specific package

cargo fmt -p [package]

Show diff of changes

cargo fmt -- --emit diff

Format with verbose output

cargo fmt --verbose

说明

cargo fmt formats all bin and lib files of the current crate using rustfmt. Formats .rs files in src/, tests/, examples/, and integration tests. Reformats code in-place by default.

参数

--all
Format all packages in workspace
--check
Check formatting without modifying files (for CI)
-p, --package _name_
Format specific package
--manifest-path _path_
Path to Cargo.toml
-v, --verbose
Verbose output
-q, --quiet
Suppress output
-- --emit _mode_
Output mode: files, stdout, diff
-- --edition _year_
Override Rust edition

FAQ

What is the cargo-fmt command used for?

cargo fmt formats all bin and lib files of the current crate using rustfmt. Formats .rs files in src/, tests/, examples/, and integration tests. Reformats code in-place by default.

How do I run a basic cargo-fmt example?

Run `cargo fmt` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --all do in cargo-fmt?

Format all packages in workspace