DEV Community

Discussion on: From C# to Rust: Code Basics

Collapse
 
winstonpuckett profile image
Winston Puckett

I'm trying to learn rust right now and I'm really struggling with how rust does namespaces, filepaths, or whatever you want to call it. So if I have a file at the root and want to call a method in a file in a subfolder, I can't figure out how. Would you make an in depth guide around namespaces (or whatever it's called) in rust? And if you do, would you let me know?

Collapse
 
sebnilsson profile image
Seb Nilsson • Edited

Yes, Rust's module-system is closer to the module-system in Node.js and quite different from how C# thinks about namespaces, from what I can see so far.
I will cover this in upcoming articles, with more advanced Rust concepts.

Collapse
 
tomuxmon profile image
Tomas Dambrauskas

not directly on topic but following this (dev.to/qongzi/bevy-minesweeper-int...) 12 part tutorial I now understand much more how the module system work.
notable takeaways:

  • module can be a single .rs file or a folder with mod.rs file (further describing sub modules).
  • if you want to use some module in your main.rs file you need to add mod some; on top of your `main.rs.
  • after the wiring is done you can use types declared in your external module with use some::SomeStruct;

just googled a good article about rust modules: sheshbabu.com/posts/rust-module-sy...