Skip to content

Commit aa58887

Browse files
committed
Auto merge of #33016 - tbu-:pr_doc_peekable, r=alexcrichton
Add a note about side effects for "peekable" iterators
2 parents a626400 + c29585c commit aa58887

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/libcore/iter.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -901,12 +901,17 @@ pub trait Iterator {
901901
Enumerate { iter: self, count: 0 }
902902
}
903903

904-
/// Creates an iterator which can look at the `next()` element without
905-
/// consuming it.
904+
/// Creates an iterator which can use `peek` to look at the next element of
905+
/// the iterator without consuming it.
906906
///
907907
/// Adds a [`peek()`] method to an iterator. See its documentation for
908908
/// more information.
909909
///
910+
/// Note that the underlying iterator is still advanced when `peek` is
911+
/// called for the first time: In order to retrieve the next element,
912+
/// `next` is called on the underlying iterator, hence any side effects of
913+
/// the `next` method will occur.
914+
///
910915
/// [`peek()`]: struct.Peekable.html#method.peek
911916
///
912917
/// # Examples

0 commit comments

Comments
 (0)