add ready_find() stream extension
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
d98ec6bf46
commit
75fb19a5ca
1 changed files with 20 additions and 1 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue