File tree 1 file changed +12
-1
lines changed
1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ mod my_mod {
43
43
}
44
44
45
45
// Functions declared using `pub(self)` syntax are only visible within
46
- // the current module
46
+ // the current module, which is the same as leaving them private
47
47
pub(self) fn public_function_in_nested() {
48
48
println!("called `my_mod::nested::public_function_in_nested");
49
49
}
@@ -73,6 +73,13 @@ mod my_mod {
73
73
pub fn function() {
74
74
println!("called `my_mod::private_nested::function()`");
75
75
}
76
+
77
+ // Private parent items will still restrict the visibility of a child item,
78
+ // even if it is declared as visible within a bigger scope.
79
+ #[allow(dead_code)]
80
+ pub(crate) fn restricted_function() {
81
+ println!("called `my_mod::private_nested::restricted_function()`");
82
+ }
76
83
}
77
84
}
78
85
@@ -113,5 +120,9 @@ fn main() {
113
120
// Error! `private_nested` is a private module
114
121
//my_mod::private_nested::function();
115
122
// TODO ^ Try uncommenting this line
123
+
124
+ // Error! `private_nested` is a private module
125
+ //my_mod::private_nested::restricted_function();
126
+ // TODO ^ Try uncommenting this line
116
127
}
117
128
```
You can’t perform that action at this time.
0 commit comments