Skip to content

Commit e7db51b

Browse files
committed
Add warning on while let syntax
1 parent a6a4c60 commit e7db51b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
//! }
1616
//! ```
1717
//!
18+
//! However, **make sure to only use the above form with a mutable reference to an existing iterator**.
19+
//! For example, the following code will loop forever over the first element of the array:
20+
//!
21+
//! ```ignore
22+
//! let array = [0, 1, 2, 3];
23+
//! while let Some(item) = convert(array.iter()).next() {
24+
//! // This is an infinite loop!
25+
//! }
26+
//! ```
27+
//!
1828
//! While the standard `Iterator` trait's functionality is based off of the `next` method,
1929
//! `StreamingIterator`'s functionality is based off of a pair of methods: `advance` and `get`. This
2030
//! essentially splits the logic of `next` in half (in fact, `StreamingIterator`'s `next` method

0 commit comments

Comments
 (0)