January 2019
Intermediate to advanced
520 pages
14h 32m
English
Stream is a trait that represents a sequence of deferred items. It works in a similar way to the Iterator trait, but it uses the poll method to get the next Item or to return Error in the case of failure. The stream can either be incoming data from a socket or data that can be read from a file. Stream can be converted to Future and vice versa if the Future instance returns a Stream.
To use streams effectively, you should learn the methods of the StreamExt trait. This lets you make a chain to process every item of the stream or even join multiple streams into one. For example, you can filter some elements from Stream using the filter method with a predicate:
let stream = stream::iter_ok::<_, ()>(vec![-1, 0, 1, 2, 3
Read now
Unlock full access