Skip to content

Commit 10387d6

Browse files
committed
Rollup merge of #27286 - lastorset:pub, r=steveklabnik
The reader could probably infer this from the current text, but for C++ programmers it's not obvious that struct fields don't automatically become public. Apparently I wasn't the only one to be confused: http://stackoverflow.com/questions/29157300/field-of-struct-is-private-when-importing-module I don't think an example is necessary, but can add one if desired. r? @steveklabnik
2 parents e6ed27b + 95c7f30 commit 10387d6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/doc/trpl/crates-and-modules.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ Hello in English: Hello!
355355
Goodbye in English: Goodbye.
356356
```
357357
358+
`pub` also applies to `struct`s and their member fields. In keeping with Rust’s
359+
tendency toward safety, simply making a `struct` public won't automatically
360+
make its members public: you must mark the fields individually with `pub`.
361+
358362
Now that our functions are public, we can use them. Great! However, typing out
359363
`phrases::english::greetings::hello()` is very long and repetitive. Rust has
360364
another keyword for importing names into the current scope, so that you can

0 commit comments

Comments
 (0)