Crate streaming_iterator [] [src]

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
}

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.

Structs

Cloned

A normal, non-streaming, iterator which converts the elements of a streaming iterator into owned values by cloning them.

Convert

A streaming iterator which yields elements from a normal, non-streaming, iterator.

Filter

A streaming iterator which filters the elements of a streaming iterator with a predicate.

FilterMap

An iterator which both filters and maps elements of a streaming iterator with a closure.

Fuse

A streaming iterator which is well-defined before and after iteration.

Map

A streaming iterator which transforms the elements of a streaming iterator.

MapRef

A streaming iterator which transforms the elements of a streaming iterator.

Skip

A streaming iterator which skips a number of elements in a streaming iterator.

SkipWhile

A streaming iterator which skips initial elements that match a predicate

Take

A streaming iterator which only yields a limited number of elements in a streaming iterator.

TakeWhile

A streaming iterator which only returns initial elements matching a predicate.

Traits

StreamingIterator

An interface for dealing with streaming iterators.

Functions

convert

Turns a normal, non-streaming iterator into a streaming iterator.