Runtime model
Streams are similar to futures, but instead of yielding a single value, theyasynchronously yield one or more values. They can be thought of as asynchronousiterators.
The Stream trait
Just like , implementing Stream
is common when using Tokio. Streamsyield many values, so lets start with a stream that generates the fibonacci sequence.
The Item
associated type is the type yielded by the stream. The associated type is the type of the error yielded when something unexpectedhappens. The poll
function is very similar to Future
’s poll
function. Theonly difference is that, this time, is returned.
Next up: