add ready_find() stream extension
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
ce6e5e48de
commit
7cf61b5b7b
1 changed files with 20 additions and 1 deletions
|
@ -2,7 +2,7 @@
|
||||||
#![allow(clippy::type_complexity)]
|
#![allow(clippy::type_complexity)]
|
||||||
|
|
||||||
use futures::{
|
use futures::{
|
||||||
future::{Ready, ready},
|
future::{FutureExt, Ready, ready},
|
||||||
stream::{
|
stream::{
|
||||||
All, Any, Filter, FilterMap, Fold, ForEach, Scan, SkipWhile, Stream, StreamExt, TakeWhile,
|
All, Any, Filter, FilterMap, Fold, ForEach, Scan, SkipWhile, Stream, StreamExt, TakeWhile,
|
||||||
},
|
},
|
||||||
|
@ -26,6 +26,12 @@ where
|
||||||
where
|
where
|
||||||
F: Fn(Item) -> bool;
|
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>(
|
fn ready_filter<'a, F>(
|
||||||
self,
|
self,
|
||||||
f: F,
|
f: F,
|
||||||
|
@ -111,6 +117,19 @@ where
|
||||||
self.any(move |t| ready(f(t)))
|
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]
|
#[inline]
|
||||||
fn ready_filter<'a, F>(
|
fn ready_filter<'a, F>(
|
||||||
self,
|
self,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue