-
Notifications
You must be signed in to change notification settings - Fork 0
/
Visibility.rs
46 lines (41 loc) · 1022 Bytes
/
Visibility.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
fn function(){
println!("called `function()`");
}
mod my{
//a public function
pub fn function(){
println!("called `my::function()`");
}
//a private function
fn private_function(){
println!("called `my::private_function()`");
}
//items can access other items in the same module
pub fn indirect_access(){
print!("called `my::indirect_access()`");
private_function();
}
//a public module
pub mod nested{
pub fn function(){
println!("called `my::nested::function()`");
}
#[allow(dead_code)]
fn private_function(){
println!("called `my::nested::private_function()`");
}
}
//a inaccessible
mod inaccessible{
#[allow(dead_code)]
pub fn public_function(){
println!("called `my::inaccessible::public_function()`");
}
}
}
fn main() {
my::function();
function();
my::indirect_access();
my::nested::function();
}