File hierarchy
Modules can be mapped to a file/directory hierarchy.
$ tree .
.
|-- my
| |-- inaccessible.rs
| |-- mod.rs
| `-- nested.rs
`-- split.rs
// split.rs
// 这里的声明将会寻找一个文件`my.rs`或者`my/mod.rs`
// 并且将该文件的内容插入到当前的运行环境
mod my;
fn function() {
println!("called `function()`");
}
fn main() {
my::function();
function();
my::indirect_access();
my::nested::function();
}
// my/mod.rs
// `mod inaccessible` and `mod nested`都或定位文件`nested.rs`
// 和`inaccessible.rs`,并将它们的所有内容插入到各自的模块命名里面
mod inaccessible;
pub mod nested;
pub fn function() {
println!("called `my::function()`");
}
fn private_function() {
println!("called `my::private_function()`");
}
pub fn indirect_access() {
print!("called `my::indirect_access()`, that\n> ");
private_function();
}
// my/nested.rs
pub fn function() {
println!("called `my::nested::function()`");
}
#[allow(dead_code)]
fn private_function() {
println!("called `my::nested::private_function()`");
}
// my/inaccessible.rs
#[allow(dead_code)]
pub fn public_function() {
println!("called `my::inaccessible::public_function()`");
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。