Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/mod/visibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod my_mod {
}

// Functions declared using `pub(self)` syntax are only visible within
// the current module
// the current module, which is the same as leaving them private
pub(self) fn public_function_in_nested() {
println!("called `my_mod::nested::public_function_in_nested");
}
Expand Down Expand Up @@ -73,6 +73,13 @@ mod my_mod {
pub fn function() {
println!("called `my_mod::private_nested::function()`");
}

// Private parent items will still restrict the visibility of a child item,
// even if it is declared as visible within a bigger scope.
#[allow(dead_code)]
pub(crate) fn restricted_function() {
println!("called `my_mod::private_nested::restricted_function()`");
}
}
}

Expand Down Expand Up @@ -113,5 +120,9 @@ fn main() {
// Error! `private_nested` is a private module
//my_mod::private_nested::function();
// TODO ^ Try uncommenting this line

// Error! `private_nested` is a private module
//my_mod::private_nested::restricted_function();
// TODO ^ Try uncommenting this line
}
```