mirror of https://github.com/rust-lang/book
Ch. 17: clarify 'in order to compile'
This commit is contained in:
parent
d6adb1e276
commit
2320e43bfc
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue