async_itertools/
lib.rs

1//! `itertools` for `Stream`s. Work-in-progress.
2//!
3//! Made with [`futures-lite`](<https://docs.rs/futures-lite/2.6.1>) in mind rather than
4//! [`futures-util`](<https://docs.rs/futures-util/0.3.31>).
5//!
6//! Large parts of the code are taken from [the original crate](<https://docs.rs/itertools/0.14.0>).
7//! Their licenses:
8//!
9//! - [MIT](<https://github.com/rust-itertools/itertools/blob/6bd5053fca990a8c7a3de6429faa53fef81de41d/LICENSE-MIT>)
10//! - [Apache-2.0](<https://github.com/rust-itertools/itertools/blob/6bd5053fca990a8c7a3de6429faa53fef81de41d/LICENSE-APACHE>)
11
12#![no_std]
13
14use futures_lite::Stream;
15
16pub use self::{features::zip_longest::zip_longest, types::either_or_both::EitherOrBoth};
17
18mod features;
19mod internal;
20mod types;
21
22/// `Itertools` extension trait but for [`Stream`]s instead of [`Iterator`]s.
23pub trait AsyncItertools: Stream {
24    /// Yields pairs, [`EitherOrBoth::Both`], of items from both streams, until at least one runs
25    /// out, then either [`EitherOrBoth::Left`] (if right ends) or [`EitherOrBoth::Right`] (if left
26    /// ends).
27    fn zip_longest<U>(self, other: U) -> ZipLongest<Self, U>
28    where
29        Self: Sized,
30        U: Stream,
31    {
32        zip_longest(self, other)
33    }
34}
35
36impl<T: ?Sized + Stream> AsyncItertools for T {}
37
38/// Type for [`AsyncItertools::zip_longest`].
39pub type ZipLongest<L, R> = self::features::zip_longest::ZipLongest<L, R>;