forked from t4sk/hello-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmods.rs
More file actions
64 lines (52 loc) · 1015 Bytes
/
mods.rs
File metadata and controls
64 lines (52 loc) · 1015 Bytes
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#![allow(unused)]
mod foo {
pub fn print() {
println!("foo");
}
}
mod my {
pub fn print() {
println!("my");
}
// Private - cannot be called by main
fn f() {
println!("private");
}
// Nest modules
pub mod a {
pub fn print() {
println!("a");
}
// Public struct
pub struct S {
pub name: String,
// Private field
id: u32,
}
pub fn build(name: String) -> S {
S { name, id: 1 }
}
}
// Private module
// Cannot be called outside of this module
mod b {
pub fn print() {
println!("b");
}
}
fn g() {
b::print();
}
// Go one level up in the module tree
use super::foo;
fn call_foo_print() {
foo::print();
}
}
use my::a::print as a_print;
fn main() {
my::print();
my::a::print();
a_print();
let s = my::a::build("rust".to_string());
}