Merge pull request #3892 from rust-lang/chriskrycho/ch-17-compilation-clarification

Ch. 17: clarify 'in order to compile'
This commit is contained in:
Chris Krycho
2024-04-17 16:15:52 -06:00
committed by GitHub
+4 -4
View File
@@ -86,10 +86,10 @@ Because we’ve encapsulated the implementation details of the struct
in the future. For instance, we could use a `HashSet<i32>` instead of a
`Vec<i32>` for the `list` field. As long as the signatures of the `add`,
`remove`, and `average` public methods stay the same, code using
`AveragedCollection` wouldn’t need to change. If we made `list` public instead,
this wouldn’t necessarily be the case: `HashSet<i32>` and `Vec<i32>` have
different methods for adding and removing items, so the external code would
likely have to change if it were modifying `list` directly.
`AveragedCollection` wouldn’t need to change in order to compile. If we made
`list` public instead, this wouldn’t necessarily be the case: `HashSet<i32>` and
`Vec<i32>` have different methods for adding and removing items, so the external
code would likely have to change if it were modifying `list` directly.
If encapsulation is a required aspect for a language to be considered
object-oriented, then Rust meets that requirement. The option to use `pub` or