add ready_find() stream extension

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2025-04-06 05:42:27 +00:00 committed by Jade Ellis
parent d98ec6bf46
commit 75fb19a5ca
No known key found for this signature in database
GPG key ID: 8705A2A3EBF77BD2

View file

@ -2,7 +2,7 @@
#![allow(clippy::type_complexity)]
use futures::{
future::{Ready, ready},
future::{FutureExt, Ready, ready},
stream::{
All, Any, Filter, FilterMap, Fold, ForEach, Scan, SkipWhile, Stream, StreamExt, TakeWhile,
},
@ -26,6 +26,12 @@ where
where
F: Fn(Item) -> bool;
fn ready_find<'a, F>(self, f: F) -> impl Future<Output = Option<Item>> + Send
where
Self: Send + Unpin + 'a,
F: Fn(&Item) -> bool + Send + 'a,
Item: Send;
fn ready_filter<'a, F>(
self,
f: F,
@ -111,6 +117,19 @@ where
self.any(move |t| ready(f(t)))
}
#[inline]
fn ready_find<'a, F>(self, f: F) -> impl Future<Output = Option<Item>> + Send
where
Self: Send + Unpin + 'a,
F: Fn(&Item) -> bool + Send + 'a,
Item: Send,
{
self.ready_filter(f)
.take(1)
.into_future()
.map(|(curr, _next)| curr)
}
#[inline]
fn ready_filter<'a, F>(
self,