additional stream extensions for any/all

additional stream extension TryBroadbandExt

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-12-04 02:11:43 +00:00
parent c2d97aaa5e
commit 59d5e3ebf1
6 changed files with 121 additions and 5 deletions

View file

@ -3,7 +3,7 @@
use futures::{
future::{ready, Ready},
stream::{Any, Filter, FilterMap, Fold, ForEach, Scan, SkipWhile, Stream, StreamExt, TakeWhile},
stream::{All, Any, Filter, FilterMap, Fold, ForEach, Scan, SkipWhile, Stream, StreamExt, TakeWhile},
};
/// Synchronous combinators to augment futures::StreamExt. Most Stream
@ -16,6 +16,10 @@ pub trait ReadyExt<Item>
where
Self: Stream<Item = Item> + Send + Sized,
{
fn ready_all<F>(self, f: F) -> All<Self, Ready<bool>, impl FnMut(Item) -> Ready<bool>>
where
F: Fn(Item) -> bool;
fn ready_any<F>(self, f: F) -> Any<Self, Ready<bool>, impl FnMut(Item) -> Ready<bool>>
where
F: Fn(Item) -> bool;
@ -66,6 +70,14 @@ impl<Item, S> ReadyExt<Item> for S
where
S: Stream<Item = Item> + Send + Sized,
{
#[inline]
fn ready_all<F>(self, f: F) -> All<Self, Ready<bool>, impl FnMut(Item) -> Ready<bool>>
where
F: Fn(Item) -> bool,
{
self.all(move |t| ready(f(t)))
}
#[inline]
fn ready_any<F>(self, f: F) -> Any<Self, Ready<bool>, impl FnMut(Item) -> Ready<bool>>
where