After reading this
I'm wondering why is there "mod" keyword and mod.rs
? The folder hierarchy can describe the module as well?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
There are a couple of reasons why modules must be explicitly declared:
Modules can be public (
pub mod foo;
) or private (mod foo;
).They can have attributes applied to them, attributes that couldn’t sit inside the file; there are two primary examples of that:
#[path = "x.rs"]
specifying a different path, and#[cfg(…)]
, for conditional compilation, for cases where the module would fail to parse or have its macros expand.
回答2:
While it can, it can also be overridden:
#[path = "somewhere/else"]
mod lol;