Rust source를 표준 style로 format하고 CI에서 format drift를 검사하는 official component.
rustup의 default profile에는 보통 포함된다. 빠져 있다면 현재 toolchain에 component를 추가한다.
rustup component add rustfmt
rustfmt --version
cargo fmt [options] [-- rustfmt-options] rustfmt [options] file...
cargo fmt [options…]rustfmt [options…] FILE…cargo fmt cargo fmt --all cargo fmt --all -- --check rustfmt src/main.rs rustfmt --edition 2024 src/main.rs
project 또는 상위 directory에 rustfmt.toml이나 .rustfmt.toml을 둔다.
edition = "2024" max_width = 100 newline_style = "Auto" use_small_heuristics = "Default"
stable toolchain에서 사용할 config는 stable option만 사용한다. nightly-only option을 공유 config에 넣으면 CI와 contributor 환경에서 실패할 수 있다.
cargo fmt --all -- --check
–check는 file을 수정하지 않고 차이가 있으면 non-zero exit status를 반환하므로 CI에 적합하다.
cargo +nightly fmt가 실패하면 해당 toolchain에 component를 추가한다.Cargo.toml의 package edition과 rustfmt config를 확인한다.로컬 실행 파일이 없어 live output을 수집하지 않았다. cargo fmt --help rustfmt --help rustfmt --print-config default /tmp/rustfmt.toml
+