You are not logged in.
Pages: 1
Hello,
I started learning the Rust programming language and installed on my Arch config. But I don't really like some default formatting like 4 spaces rather tab indent or error message on non_snake_case. I found out that I can allow indent using hard_tabs=true on project folder and #![allow(non_snake_case)] but I would like to don't have to add this line on each project if possible. I would set them by default on all project. Do you know where can I find the configuration file ? There is nothing on /etc/rustup or /etc/cargo or on ~/.config/ folders.
Thank you.
Offline
rustfmt looks for a file named rustfmt.toml or .rustfmt.toml in any parent directory. So if you have a directory that stores all your projects, you don't need to put a config file in every project; you can just put it in the parent directory.
allow(non_snake_case) is not a rustfmt directive; it is the compiler itself that checks naming conventions. So I think you have to override it on a per-project basis. But if you can, I would encourage you to just adopt the suggested naming style; even if it's not your favorite, there's value in following language convention when it comes to naming things, especially if you intend to ever publish this code in some way. Nobody likes that guy who writes Python in C#-style.
Personally the only thing I have overridden in any of my projects is hard_tabs = true.
Last edited by Trent (2020-03-21 16:25:40)
Offline
If I put rustfmt.toml with hard_subs=true on parent folder and then create a new project with cargo, the file main.rs have spaces instead of tabs by default. I suppose, this is not an issue and I just have to replace on each new project on first use. Right ?
Thanks.
Offline
True, cargo init does not run rustfmt for you, but it will be fixed the next time you run cargo fmt.
Offline
Okay, thank you.
Offline
Pages: 1