Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there a mod keyword in Rust?

Tags:

module

rust

After reading this I'm wondering why is there "mod" keyword and mod.rs? The folder hierarchy can describe the module as well?

like image 387
bitnick Avatar asked Sep 28 '15 01:09

bitnick


People also ask

What does Pub mod do in Rust?

pub(super) makes an item visible to the parent module. This is equivalent to pub(in super) . pub(self) makes an item visible to the current module. This is equivalent to pub(in self) or not using pub at all.

How do you import a module in Rust?

To import the module, we use the keyword mod , followed by the file name without the . rs extension. When a module is imported, it allows us to use any code that's marked as public in the file we're importing the module from. Note that the module must be imported before we use any of its code.

How do you organize a Rust project?

Rust projects are organized into crates which form a single distribution unit, like a static object or a DLL. Source within a crate is organized into modules, which are like namespaces but provide an additional privacy boundary. Not everything in a module has to be publicly exported to other modules.


1 Answers

While it can, it can also be overridden:

#[path = "somewhere/else"]
mod lol;
like image 81
Steve Klabnik Avatar answered Sep 28 '22 03:09

Steve Klabnik