@@ -35,6 +35,7 @@ mod my_mod {
35
35
}
36
36
37
37
// Modules can also be nested
38
+ // モジュールもネストできる
38
39
pub mod nested {
39
40
pub fn function() {
40
41
println!("called `my_mod::nested::function()`");
@@ -47,19 +48,24 @@ mod my_mod {
47
48
48
49
// Functions declared using `pub(in path)` syntax are only visible
49
50
// within the given path. `path` must be a parent or ancestor module
51
+ // `pub(in path)`形式で宣言された関数は該当のパス内でのみアクセスできる。
52
+ // `path`は親や先祖のモジュールでなくてはならない。
50
53
pub(in crate::my_mod) fn public_function_in_my_mod() {
51
54
print!("called `my_mod::nested::public_function_in_my_mod()`, that\n> ");
52
55
public_function_in_nested();
53
56
}
54
57
55
58
// Functions declared using `pub(self)` syntax are only visible within
56
59
// the current module, which is the same as leaving them private
60
+ // `pub(self)`形式で宣言された関数は現在のモジュール内でのみアクセスできる。
61
+ // つまり、プライベートにするのと同じである。
57
62
pub(self) fn public_function_in_nested() {
58
63
println!("called `my_mod::nested::public_function_in_nested()`");
59
64
}
60
65
61
66
// Functions declared using `pub(super)` syntax are only visible within
62
67
// the parent module
68
+ // `pub(super)`形式で宣言された関数は親モジュール内でのみアクセスできる。
63
69
pub(super) fn public_function_in_super_mod() {
64
70
println!("called `my_mod::nested::public_function_in_super_mod()`");
65
71
}
@@ -73,6 +79,7 @@ mod my_mod {
73
79
}
74
80
75
81
// pub(crate) makes functions visible only within the current crate
82
+ // pub(crate)により関数は現在のクレート内でのみアクセスできる。
76
83
pub(crate) fn public_function_in_crate() {
77
84
println!("called `my_mod::public_function_in_crate()`");
78
85
}
@@ -87,6 +94,8 @@ mod my_mod {
87
94
88
95
// Private parent items will still restrict the visibility of a child item,
89
96
// even if it is declared as visible within a bigger scope.
97
+ // 親がプライベートな場合、子要素がより大きなスコープでアクセスできるように宣言されていても、
98
+ // 子要素にアクセス可能な範囲は制限されます。
90
99
#[allow(dead_code)]
91
100
pub(crate) fn restricted_function() {
92
101
println!("called `my_mod::private_nested::restricted_function()`");
@@ -113,12 +122,16 @@ fn main() {
113
122
my_mod::call_public_function_in_my_mod();
114
123
115
124
// pub(crate) items can be called from anywhere in the same crate
125
+ // pub(crate)の要素は同じクレートのどこからでも呼び出すことができる。
116
126
my_mod::public_function_in_crate();
117
127
118
128
// pub(in path) items can only be called from within the module specified
119
129
// Error! function `public_function_in_my_mod` is private
130
+ // pub(in path)の要素は指定されたモジュールからのみ呼び出すことができる。
131
+ // エラー! `public_function_in_my_mod`関数はプライベート。
120
132
//my_mod::nested::public_function_in_my_mod();
121
133
// TODO ^ Try uncommenting this line
134
+ // TODO ^ 試しにこの行をアンコメントしてみましょう。
122
135
123
136
// Private items of a module cannot be directly accessed, even if
124
137
// nested in a public module:
@@ -138,13 +151,15 @@ fn main() {
138
151
// TODO ^ 試しにこの行をアンコメントしてみましょう。
139
152
140
153
// Error! `private_nested` is a private module
141
- // エラー!`private_nested`はプライベートなモジュール 。
154
+ // エラー!`private_nested`はプライベートなモジュール。
142
155
//my_mod::private_nested::function();
143
156
// TODO ^ Try uncommenting this line
144
157
// TODO ^ 試しにこの行をアンコメントしてみましょう。
145
158
146
159
// Error! `private_nested` is a private module
160
+ // エラー! `private_nested`はプライベートなモジュール。
147
161
//my_mod::private_nested::restricted_function();
148
162
// TODO ^ Try uncommenting this line
163
+ // TODO ^ 試しにこの行をアンコメントしてみましょう。
149
164
}
150
165
```
0 commit comments