//! Synchronous combinator extensions to futures::TryStream #![allow(clippy::type_complexity)] use futures::{ future::{ready, Ready}, stream::{AndThen, TryForEach, TryStream, TryStreamExt}, }; use crate::Result; /// Synchronous combinators to augment futures::TryStreamExt. /// /// This interface is not necessarily complete; feel free to add as-needed. pub trait TryReadyExt where S: TryStream> + Send + ?Sized, Self: TryStream + Send + Sized, { fn ready_and_then(self, f: F) -> AndThen>, impl FnMut(S::Ok) -> Ready>> where F: Fn(S::Ok) -> Result; fn ready_try_for_each( self, f: F, ) -> TryForEach>, impl FnMut(S::Ok) -> Ready>> where F: FnMut(S::Ok) -> Result<(), E>; } impl TryReadyExt for S where S: TryStream> + Send + ?Sized, Self: TryStream + Send + Sized, { #[inline] fn ready_and_then(self, f: F) -> AndThen>, impl FnMut(S::Ok) -> Ready>> where F: Fn(S::Ok) -> Result, { self.and_then(move |t| ready(f(t))) } #[inline] fn ready_try_for_each( self, mut f: F, ) -> TryForEach>, impl FnMut(S::Ok) -> Ready>> where F: FnMut(S::Ok) -> Result<(), E>, { self.try_for_each(move |t| ready(f(t))) } }