10 releases
Uses new Rust 2024
| new 0.0.12 | Feb 8, 2026 |
|---|---|
| 0.0.11 | Feb 6, 2026 |
| 0.0.8 | Jan 16, 2026 |
#1076 in Command line utilities
55KB
1.5K
SLoC
cargo-fmt-toml
Cargo subcommand to format and normalize Cargo.toml files according
to workspace standards.
Installation
Using cargo-binstall (Recommended)
The fastest way to install pre-built binaries:
cargo install cargo-binstall
cargo binstall cargo-fmt-toml
Using cargo install
Build from source (slower, requires Rust toolchain):
cargo install cargo-fmt-toml
Features
- Workspace Dependencies: Ensures all dependency versions are managed at workspace level
- Internal Dependencies: All workspace crates use
{ workspace = true }for consistency - Sorted Dependencies: All dependency sections are sorted alphabetically by name
- Package Section Format: Enforces a consistent
[package]section format
Usage
# Format all Cargo.toml files in the workspace
cargo fmt-toml
# Preview changes without modifying files
cargo fmt-toml --dry-run
# Check if files need formatting (returns non-zero if changes
# needed)
cargo fmt-toml --check
Package Section Format
The tool enforces this exact format for the [package] section:
[package]
name = "crate-name"
description = "Brief description"
version = { workspace = true }
edition = { workspace = true }
license-file = { workspace = true }
authors = { workspace = true }
rust-version = { workspace = true }
readme = { workspace = true }
Dependency Sorting
All dependency sections are sorted alphabetically:
[dependencies][dev-dependencies][build-dependencies][target.'cfg(...)'.dependencies]
Integration
Add to your Makefile:
.PHONY: fmt-toml
fmt-toml:
@cargo run --package cargo-fmt-toml
.PHONY: check-fmt-toml
check-fmt-toml:
@cargo run --package cargo-fmt-toml -- --check
Dependencies
~33–62MB
~1M SLoC