mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-07 10:06:22 +02:00
Add speaker notes for visibility. (#348)
This commit is contained in:
parent
9fe0b68a2d
commit
957f2a70f0
@ -4,6 +4,8 @@ Modules are a privacy boundary:
|
|||||||
|
|
||||||
* Module items are private by default (hides implementation details).
|
* Module items are private by default (hides implementation details).
|
||||||
* Parent and sibling items are always visible.
|
* Parent and sibling items are always visible.
|
||||||
|
* In other words, if an item is visible in module `foo`, it's visible in all the
|
||||||
|
descendants of `foo`.
|
||||||
|
|
||||||
```rust,editable
|
```rust,editable
|
||||||
mod outer {
|
mod outer {
|
||||||
@ -31,8 +33,16 @@ fn main() {
|
|||||||
outer::public();
|
outer::public();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
|
|
||||||
* Use the `pub` keyword to make mods public.
|
* Use the `pub` keyword to make mods public.
|
||||||
|
|
||||||
|
Additionally, there are advanced `pub(...)` specifiers to restrict the scope of public visibility.
|
||||||
|
|
||||||
|
* See the [Rust Reference](https://doc.rust-lang.org/reference/visibility-and-privacy.html#pubin-path-pubcrate-pubsuper-and-pubself)).
|
||||||
|
* Configuring `pub(crate)` visibility is a common pattern.
|
||||||
|
* Less commonly, you can give visibility to a specific path.
|
||||||
|
* In any case, visibility must be granted to an ancestor module (and all of its descendants).
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user