Document visibility in the manual/tutorial
This removes the warning "Note" about visibility not being fully defined, as it should now be considered fully defined with further bugs being considered just bugs in the implementation.
This commit is contained in:
@@ -2322,19 +2322,18 @@ fn main() {
|
||||
|
||||
The `::farm::chicken` construct is what we call a 'path'.
|
||||
|
||||
Because it's starting with a `::`, it's also a 'global path',
|
||||
which qualifies an item by its full path in the module hierarchy
|
||||
relative to the crate root.
|
||||
Because it's starting with a `::`, it's also a 'global path', which qualifies
|
||||
an item by its full path in the module hierarchy relative to the crate root.
|
||||
|
||||
If the path were to start with a regular identifier, like `farm::chicken`, it would be
|
||||
a 'local path' instead. We'll get to them later.
|
||||
If the path were to start with a regular identifier, like `farm::chicken`, it
|
||||
would be a 'local path' instead. We'll get to them later.
|
||||
|
||||
Now, if you actually tried to compile this code example, you'll notice
|
||||
that you get a `unresolved name: 'farm::chicken'` error. That's because per default,
|
||||
items (`fn`, `struct`, `static`, `mod`, ...) are only visible inside the module
|
||||
they are defined in.
|
||||
Now, if you actually tried to compile this code example, you'll notice that you
|
||||
get a `function 'chicken' is private` error. That's because by default, items
|
||||
(`fn`, `struct`, `static`, `mod`, ...) are private.
|
||||
|
||||
To make them visible outside their containing modules, you need to mark them _public_ with `pub`:
|
||||
To make them visible outside their containing modules, you need to mark them
|
||||
_public_ with `pub`:
|
||||
|
||||
~~~~
|
||||
mod farm {
|
||||
@@ -2356,7 +2355,8 @@ Rust doesn't support encapsulation: both struct fields and methods can
|
||||
be private. But this encapsulation is at the module level, not the
|
||||
struct level.
|
||||
|
||||
For convenience, fields are _public_ by default, and can be made _private_ with the `priv` keyword:
|
||||
For convenience, fields are _public_ by default, and can be made _private_ with
|
||||
the `priv` keyword:
|
||||
|
||||
~~~
|
||||
mod farm {
|
||||
@@ -2393,7 +2393,8 @@ fn main() {
|
||||
# fn make_me_a_chicken() -> farm::Chicken { 0 }
|
||||
~~~
|
||||
|
||||
> ***Note:*** Visibility rules are currently buggy and not fully defined, you might have to add or remove `pub` along a path until it works.
|
||||
Exact details and specifications about visibility rules can be found in the Rust
|
||||
manual.
|
||||
|
||||
## Files and modules
|
||||
|
||||
|
||||
Reference in New Issue
Block a user