Skip to content

Commit 605a279

Browse files
authored
Merge pull request #14 from Palladinium/while-let-warning
Add warning on while let syntax
2 parents a6a4c60 + 5db671c commit 605a279

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/lib.rs

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

0 commit comments

Comments
 (0)