Rust's Formatter for vscode

I am using Visual Studio Code and using the Rust's default formatter, and if I were to press shift+alt+F it will look like this.

fn main() {
    println!("Hello World");
}

How do I override the settings to look like this.

fn main()
{
    println!("Hello World");
}

You can add a rustfmt.toml to your project's directory or a few others places and specify the brace_style.

1 Like

I am in htis directory C:\Users\%username%\AppData\Roaming. Do you know where do I go to modify the global file that controls the Rustfmt?

You just have to create a new directory there called rustfmt with a rustfmt.toml inside.

Ok so I did that, do I put this inside the new cargo.toml file?

brace_style: "AlwaysNextLine";

I am kinda new to all of this so I don't have much of an understanding.

No, you put it in the rustfmt.toml you creates in C:\Users\%username%\AppData\Roaming\rustfmt, and no need for the ; at the end.

Also I just saw you need to use the nightly version of rustfmt to use this specific option.
You can do it by choosing the nightly toolchain as default or call cargo with +nightly. (cargo +nightly fmt)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.