Rustidy - A rust formatter

Hello, this is a project I've been working on for a few months now and I'm finally ready to release.

Repository: GitHub - Zenithsiz/rustidy

This is a formatter for rust code, as an alternative to rustfmt.
It does not re-use any of rustfmt's parts and re-implements parsing, formatting and printing.

The repository has some more details, but here are the "killer features" over rustfmt:

Changing configuration with a attribute

// Change the threshold for splitting an array into multi-line.
#[rustidy::config(max_array_expr_len = 100)]
const ARRAY: [u32; 25] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25];
#[rustidy::config(max_array_expr_len = 0)]
const ARRAY: [u32; 2] = [
	1,
	2,
];

// Format an array with columns
#[rustidy::config(array_expr_cols = 3)]
const ARRAY: [u32; 8] = [
	1, 2, 3,
	4, 5, 6,
	7, 8,
]

// Change the indentation on a part of the code
#[rustidy::config(indent = "  ")]
fn main() {
  println!("Hello world!");
}
#[rustidy::config(indent = "\t\t")]
fn main() {
		println!("Hello world!");
}

Formatting expressions inside of derive macro attributes:

#[derive(derive_more::Debug)]
// The expression inside of this will be formatted.
#[debug("{:?}", match ... {
	... => ...
	... => ...
})]
struct A { ... }

Disclaimer: To use the attributes you'll need to run nightly rust, but if you don't use the attributes you can run the formatter on stable.

In the future, I'll also be implementing formatting of expressions inside of macro calls (and maybe macro definitions!).

And for the record, I'd like to point out this is not vibecoded, nor was any generative AI used for it's development.

I'd love to get some feedback, thank you!

2 Likes

Recently I finished integration of my IDE with Rustfmt, but I did it extremely flexible, so any source formatter will work if

  1. it supports CLI ending with Rust file path
  2. it supports input as stdin and out as stdout when no file path specified

Unfortunately, I do not have Cargo installed, and it is unclear for which platform you provided binary in the release section og GitHub.. Please, do the next release for such popular platforms as Windows, Linux and MacOS. I am already your user, because I do not like Rustfmt formatting style.

Thank you.

rustidy supports both receiving files via arguments to format in-place and also via stdin/stdout (if no files are passed), so it should work.

The current releases in github are for linux only. In future releases I'll include that in the name and attempt to cross compile for windows.

Awesome, thanks.

Since I develop on Raspberry Pi, Arm64 support has more sense for me.