A tool for ordering derives in Rust code.
cargo-derivefmt ensures that your derives are written in alphabetical order.
// Before: pure chaos.
#[derive(Debug, PartialEq, Ord, Clone, Copy)]
struct S;
// After: blissful order.
#[derive(Clone, Copy, Debug, Ord, PartialEq)]
struct S;That's it! That's all this does.
This package is currently implemented using rust-analyzer internals, so cannot be published on crates.io.
cargo install --locked --git https://github.com/dcchut/cargo-derivefmt --bin cargo-derivefmtcargo derivefmt cargo derivefmt --manifest-path /path/to/Cargo.tomlcargo derivefmt --file path/to/src.rscargo derivefmt --file path/to/src.rs --file /path/to/another.rsPassing a folder formats all .rs files contained within it and its subfolders:
cargo derivefmt --file /path/to/folder/- Better identification of files to format (particularly in the context of a cargo project).
- Better handling of comments.