heim_common/utils/stream.rs
1//! `futures::Stream` extensions
2
3use crate::prelude::Stream;
4
5mod choose_chain;
6
7pub use self::choose_chain::ChooseChain;
8
9/// heim-specific extensions for `futures::Stream`.
10pub trait HeimStreamExt: Stream {
11 /// Yields items from the `Self`, and if `Self` yield nothing,
12 /// yields from `other` then.
13 ///
14 /// If `Self` yielded at least one item, `other` will not be polled at all.
15 fn choose_chain<St>(self, other: St) -> ChooseChain<Self, St>
16 where
17 St: Stream<Item = Self::Item>,
18 Self: Sized,
19 {
20 ChooseChain::new(self, other)
21 }
22}
23
24impl<T> HeimStreamExt for T where T: Stream {}