Expand description
infinite-stream is a Rust library for streams (asynchronous iterators) that always keep yielding items (or panic, or become pending forever). This means that the return type of the next future is Self::Item instead of Option<Self::Item>, for example, which lets you skip handling the None case.
Besides manually implementing the InfiniteStream trait, this crate currently offers the following ways to construct an infinite stream:
- An
expectextension method on regular (possibly finite) streams, which returns a wrapper stream that panics ifNoneis yielded from the inner stream. - A
pendingfunction which returns an infinite stream that never yields any items, and achain_pendingmethod on regular streams which becomes pending after the inner stream is exhausted. - The functions
unfoldandtry_unfoldwhich are similar to the ones for regular streams. - The functions
from_futureandtry_from_futurewhich turn a future that resolves to an infinite stream into an infinite stream yielding the same items.
This crate’s implementation is heavily based on the implementation of the Stream trait and related helpers from the futures crate. However, this crate is in early stages of development and doesn’t offer equivalents for most of the helpers from futures yet. Pull requests are welcome.