Skip to content

Chapter 12.5 - struct Config is made public for no reason? #4524

@NeatNit

Description

@NeatNit
  • I have searched open and closed issues and pull requests for duplicates, using these search terms:
    • pub struct Config
  • I have checked the latest main branch 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,
}

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,
}

// 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions