-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Description
- I have searched open and closed issues and pull requests for duplicates, using these search terms:
- pub struct Config
- I have checked the latest
mainbranch to see if this has already been fixed, in this file:- /listings/ch12-an-io-project/listing-12-22/src/main.rs
URL to the section(s) of the book with this problem:
Just above https://doc.rust-lang.org/book/ch12-05-working-with-environment-variables.html#listing-12-22
Description of the problem:
In Chapter 12.3 we created the Config struct:
struct Config {
query: String,
file_path: String,
}book/listings/ch12-an-io-project/listing-12-06/src/main.rs
Lines 23 to 26 in 555182e
| struct Config { | |
| query: String, | |
| file_path: String, | |
| } |
This struct is private, which is good: it has no reason to be public, as it's only used within main.rs.
But in Chapter 12.5 we go back to make changes to this struct, and this time we make it public for no apparent reason:
pub struct Config {
pub query: String,
pub file_path: String,
pub ignore_case: bool,
}book/listings/ch12-an-io-project/listing-12-22/src/main.rs
Lines 27 to 33 in 555182e
| // ANCHOR: here | |
| pub struct Config { | |
| pub query: String, | |
| pub file_path: String, | |
| pub ignore_case: bool, | |
| } | |
| // ANCHOR_END: here |
This is probably bad practice (I think), but more importantly, it's confusing because it's an unexplained change from a previous state.
Suggested fix:
Make struct Config private in Listing 12-22 and all following listings.
Am I missing some reason for this change?