Possible Error in Rust Programming Book, Section 9.3 To Panic! or Not To Panic!

In listing 9.10 in section 9.3, To Panic! or Not To Panic! the text indicates that the Guess struct prevents any guess outside of the range from 1 to 100. I agree that this is the case if you use the new method, but there is nothing to prevent me from doing the following:

let g = Guess { value: 1000 }; 
println!("value is {}", g.value());

Is there something missing from the text around that listing?

The field is private, so unless you're inside the same module, you can't create it like that.

1 Like

Thank you. I reread the section, and there is a mention of code outside the module, but it is buried in a single sentence inside a paragraph that discusses value being private.
Thanks again.

1 Like

If you feel the paragraph could be better worded, you should feel free to submit a PR!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.