cargo-xfmt

Crates.iocargo-xfmt
lib.rscargo-xfmt
version0.0.10
created_at2025-10-14 01:03:05.075543+00
updated_at2025-10-23 03:28:54.460503+00
descriptionSafely use nightly fmt options without using unstable Rust
homepage
repositoryhttps://github.com/alshdavid/cargo-xfmt
max_upload_size
id1881386
size37,257
David Alsh (alshdavid)

documentation

README

cargo-xfmt

This project enables the use of unstable Rust formatting options without using nightly Rust

Installation

cargo install cargo-xfmt

Usage

The same as cargo fmt

cargo xfmt
cargo xfmt --config ./path/to/rustfmt.toml

VSCode

And add this to .vscode/settings.json

{
  "rust-analyzer.rustfmt.overrideCommand": [
    "cargo", "xfmt",
  ]
}

How it works and why it's relatively safe

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.

Commit count: 0

cargo fmt