Update ch13-02-iterators.md: Clarify that consuming iterator methods do not consume the underlying collection. #4627
+5
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a small clarification to the Methods That Consume the Iterator section in Chapter 13.
The existing text correctly explains that calling a consuming adapter like sum takes ownership of the iterator and prevents it from being used afterward. However, it does not explicitly state that the underlying collection remains valid when the iterator was created using
iter().This omission can lead readers to incorrectly infer that calling sum also invalidates the original collection. The added paragraph clarifies that:
v1_iterborrowsv1sumconsumes the iterator, not the vectorv1remains usable after the call tosumA short sentence is added immediately after the existing explanation to make this distinction explicit, without introducing new concepts or changing the structure of the section.
Scope
Notes
I understand that non-error changes may be deferred to a larger revision. This PR is submitted in case the clarification is considered a small correctness improvement appropriate to include earlier.
Thank you for your time and for maintaining the book.