Note: This is my first post on this forum, so apologies if this doesn't belong here. I've been using Rust for about a year now, so I'm excited to participate in discussions about it!
Currently, there are 2 possible ways to name a module file. Either
src/name/mod.rs. After some experience in Rust, I've come to prefer the latter approach. I like keeping code that belongs together in the same directory. In my opinion this makes more sense logically, and it looks better. The part I hate, though, is the file name
mod.rs. I'd like to use just
name.rs, so it ends up being
This issue has been discussed before, the first example I found would be this thread. It seems the general consensus was against including this in Rust. I don't agree, but my question isn't about making this a language feature, my question is: is using
#[path] for normal modules bad practice? So the resulting code would look like this:
#[path="name/name.rs"] pub mod name;
I don't see anything inherently bad with this. While it may be unusual, it's pretty self explanatory, and while it adds some boilerplate, it has improved my developing experience substantially enough to start using this pattern in my whole project. I probably wouldn't do this in production code, but I've stuck to it now and I'm loving it!
Context: I've finally gotten to writing a bigger project in Rust, so I have a lot of (sub) modules. Using
mod.rs everywhere became very confusing to me, e.g. as mentioned in the linked thread, having open multiple tabs in VS Code sucks. Visually, it also makes finding the correct file in a file viewer hard. I've thought of tooling/scripting as another point (e.g.
fding an source file), but I have no example of where this is an issue.
What are your thoughts on this pattern? Do you think it'd be possible to include in the language? Should it? Thanks for reading this far :D, have a great day everyone