//! Wideband stream combinator extensions to futures::Stream use std::convert::identity; use futures::{ stream::{Stream, StreamExt}, Future, }; use super::{automatic_width, ReadyExt}; /// Concurrency extensions to augment futures::StreamExt. wideband_ combinators /// produce in-order. pub trait WidebandExt where Self: Stream + Send + Sized, { /// Concurrent filter_map(); ordered results fn widen_filter_map(self, n: N, f: F) -> impl Stream + Send where N: Into>, F: Fn(Item) -> Fut + Send, Fut: Future> + Send, U: Send; fn widen_then(self, n: N, f: F) -> impl Stream + Send where N: Into>, F: Fn(Item) -> Fut + Send, Fut: Future + Send, U: Send; #[inline] fn wide_filter_map(self, f: F) -> impl Stream + Send where F: Fn(Item) -> Fut + Send, Fut: Future> + Send, U: Send, { self.widen_filter_map(None, f) } #[inline] fn wide_then(self, f: F) -> impl Stream + Send where F: Fn(Item) -> Fut + Send, Fut: Future + Send, U: Send, { self.widen_then(None, f) } } impl WidebandExt for S where S: Stream + Send + Sized, { #[inline] fn widen_filter_map(self, n: N, f: F) -> impl Stream + Send where N: Into>, F: Fn(Item) -> Fut + Send, Fut: Future> + Send, U: Send, { self.map(f) .buffered(n.into().unwrap_or_else(automatic_width)) .ready_filter_map(identity) } #[inline] fn widen_then(self, n: N, f: F) -> impl Stream + Send where N: Into>, F: Fn(Item) -> Fut + Send, Fut: Future + Send, U: Send, { self.map(f) .buffered(n.into().unwrap_or_else(automatic_width)) } }