VSCode for multiple mod.rs files?

I like to compartmentalize modules into separate folders. However, at a glance, this means having a bunch of mod.rs files (each in their own folder).

Is there an approach to using VSCode for managing lots of mod.rs files - e.g. to draw attention more to the folder name than the file name?

In the meantime, what I've been doing is having a skeleton mod.rs that only has like:

mod foo;
pub use foo::*;

That way I can put the code in foo.rs even if it's essentially the only file in the folder.

It works, but I feel kinda silly having all these mod.rs shims floating around since the only real reason is navigating tabs in VSCode.

1 Like

This is not true in the 2018 edition - you can keep file foo.rs and directory foo at the same time. Or you don't like the idea that the module file will be at the same level as lib.rs?

1 Like

right, I'd like to put foo.rs in the foo directory (maybe this is non-standard? but it just feels cleaner to me for some reason - I guess because then all my modules are a folder, regardless if they are split between one or more files)

1 Like

This is possible with the path declaration. I think the syntax is like this

#[path = "foo/foo.rs"]
mod foo;
3 Likes

Very nice! That does do the trick... I'm not sure how much I love it since it almost feels like a signal that the module will have a completely different name... but it's definitely a step in the right direction!

btw in case anyone else lands here, this StackOverflow post gives some more tips for showing the path in VSCode: Showing path in file-tabs in Visual Studio Code - Stack Overflow

1 Like

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