Напишите свой собственный потоковый комбинатор:
use futures::{Async, Poll, Stream}; // 0.1.25
struct WhileBoth<S1, S2>(S1, S2)
where
S1: Stream,
S2: Stream<Item = S1::Item, Error = S1::Error>;
impl<S1, S2> Stream for WhileBoth<S1, S2>
where
S1: Stream,
S2: Stream<Item = S1::Item, Error = S1::Error>,
{
type Item = S1::Item;
type Error = S1::Error;
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
match self.0.poll() {
// Return errors or ready values (including the `None`
// that indicates the stream is empty) immediately.
r @ Err(_) | r @ Ok(Async::Ready(_)) => r,
// If the first stream is not ready, try the second one.
Ok(Async::NotReady) => self.1.poll(),
}
}
}
См. Также: