10 releases

0.1.9 Jan 6, 2023
0.1.8 Oct 12, 2022
0.1.7 Sep 8, 2022
0.1.6 Jun 29, 2022
0.1.2 Dec 11, 2016

#35 in Algorithms

Download history 25595/week @ 2024-01-03 24465/week @ 2024-01-10 27909/week @ 2024-01-17 26910/week @ 2024-01-24 27107/week @ 2024-01-31 27480/week @ 2024-02-07 27428/week @ 2024-02-14 27088/week @ 2024-02-21 26021/week @ 2024-02-28 26987/week @ 2024-03-06 24180/week @ 2024-03-13 29642/week @ 2024-03-20 25784/week @ 2024-03-27 26765/week @ 2024-04-03 27112/week @ 2024-04-10 23529/week @ 2024-04-17

108,557 downloads per month
Used in 179 crates (26 directly)






Streaming iterators for Rust.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


Streaming iterators.

The iterator APIs in the Rust standard library do not allow elements to be yielded which borrow from the iterator itself. That means, for example, that the std::io::Lines iterator must allocate a new String for each line rather than reusing an internal buffer. The StreamingIterator trait instead provides access to elements being iterated over only by reference rather than by value.

StreamingIterators cannot be used in Rust for loops, but while let loops offer a similar level of ergonomics:

while let Some(item) = iter.next() {
    // work with item

However, make sure to only use the above form with a mutable reference to an existing iterator, not with an expression that creates an iterator. For example, the following code will loop forever over the first element of the array:

use streaming_iterator::{convert, StreamingIterator};
let array = [0, 1, 2, 3];

while let Some(item) = convert(array.iter()).next() {
  // This is an infinite loop!

While the standard Iterator trait's functionality is based off of the next method, StreamingIterator's functionality is based off of a pair of methods: advance and get. This essentially splits the logic of next in half (in fact, StreamingIterator's next method does nothing but call advance followed by get).

This is required because of Rust's lexical handling of borrows (more specifically a lack of single entry, multiple exit borrows). If StreamingIterator was defined like Iterator with just a required next method, operations like filter would be impossible to define.

No runtime deps