@@ -145,14 +145,15 @@ expressions, types, etc.
145
145
## ` pub(in path) ` , ` pub(crate) ` , ` pub(super) ` , and ` pub(self) `
146
146
147
147
In addition to public and private, Rust allows users to declare an item as
148
- visible within a given scope. The rules for ` pub ` restrictions are as follows:
148
+ visible only within a given scope. The rules for ` pub ` restrictions are as
149
+ follows:
149
150
- ` pub(in path) ` makes an item visible within the provided ` path ` . ` path ` must
150
151
be a parent module of the item whose visibility is being declared.
151
152
- ` pub(crate) ` makes an item visible within the current crate.
152
153
- ` pub(super) ` makes an item visible to the parent module. This is equivalent
153
154
to ` pub(in super) ` .
154
155
- ` pub(self) ` makes an item visible to the current module. This is equivalent
155
- to ` pub(in self) ` .
156
+ to ` pub(in self) ` or not using ` pub ` at all .
156
157
157
158
> ** Edition Differences** : Starting with the 2018 edition, paths for
158
159
> ` pub(in path) ` must start with ` crate ` , ` self ` , or ` super ` . The 2015 edition
@@ -177,7 +178,8 @@ pub mod outer_mod {
177
178
inner_mod_visible_fn ();
178
179
}
179
180
180
- // This function is visible
181
+ // This function is visible only within `inner_mod`,
182
+ // which is the same as leaving it private.
181
183
pub (self ) fn inner_mod_visible_fn () {}
182
184
}
183
185
pub fn foo () {
@@ -209,6 +211,11 @@ fn bar() {
209
211
fn main () { bar () }
210
212
```
211
213
214
+ > ** Note:** This syntax only adds another restriction to the visibility of an
215
+ > item. It does not guarantee that the item is visible within all parts of the
216
+ > specified scope. To access an item, all of its parent items up to the
217
+ > current scope must still be visible as well.
218
+
212
219
## Re-exporting and Visibility
213
220
214
221
Rust allows publicly re-exporting items through a ` pub use ` directive. Because
0 commit comments