| Crates.io | cargo-xfmt |
| lib.rs | cargo-xfmt |
| version | 0.0.10 |
| created_at | 2025-10-14 01:03:05.075543+00 |
| updated_at | 2025-10-23 03:28:54.460503+00 |
| description | Safely use nightly fmt options without using unstable Rust |
| homepage | |
| repository | https://github.com/alshdavid/cargo-xfmt |
| max_upload_size | |
| id | 1881386 |
| size | 37,257 |
This project enables the use of unstable Rust formatting options without using nightly Rust
cargo install cargo-xfmt
The same as cargo fmt
cargo xfmt
cargo xfmt --config ./path/to/rustfmt.toml
And add this to .vscode/settings.json
{
"rust-analyzer.rustfmt.overrideCommand": [
"cargo", "xfmt",
]
}
While unstable formatting rules do change between versions of Rust, the unstable formatting rules are built into the stable version of Rust you are using and don't change unless the version of Rust is updated.
Conventionally you would use
cargo +nightly fmt
However this will download/use the nightly toolchain which is a moving target. If you use this and return to a repo after some time - formatting may fail due to a newer version of nightly Rust being installed.
That said, Cargo can be forced to use the current stable version of Rust to run the unstable formatting commands. This ensures that CI tasks that use unstable formatting always work when run against the same stable toolchain.
This is done by passing rules to cargo fmt directly. This cannot be done with a config file.
cargo fmt -- --config imports_granularity=Item --config group_imports=StdExternalCrate
This CLI tool simply wraps cargo fmt. It reads a rustfmt.toml and generates the equivalent cargo fmt command.