additional futures extension utils

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-12-31 01:11:58 +00:00
parent a3f9432da8
commit 27328cbc01
6 changed files with 123 additions and 2 deletions

View file

@ -3,7 +3,7 @@
use futures::{
future::{ready, Ready},
stream::{AndThen, TryFilterMap, TryFold, TryForEach, TryStream, TryStreamExt},
stream::{AndThen, TryFilterMap, TryFold, TryForEach, TryStream, TryStreamExt, TryTakeWhile},
};
use crate::Result;
@ -56,6 +56,13 @@ where
) -> TryForEach<Self, Ready<Result<(), E>>, impl FnMut(S::Ok) -> Ready<Result<(), E>>>
where
F: FnMut(S::Ok) -> Result<(), E>;
fn ready_try_take_while<F>(
self,
f: F,
) -> TryTakeWhile<Self, Ready<Result<bool, E>>, impl FnMut(&S::Ok) -> Ready<Result<bool, E>>>
where
F: Fn(&S::Ok) -> Result<bool, E>;
}
impl<T, E, S> TryReadyExt<T, E, S> for S
@ -122,4 +129,15 @@ where
{
self.try_for_each(move |t| ready(f(t)))
}
#[inline]
fn ready_try_take_while<F>(
self,
f: F,
) -> TryTakeWhile<Self, Ready<Result<bool, E>>, impl FnMut(&S::Ok) -> Ready<Result<bool, E>>>
where
F: Fn(&S::Ok) -> Result<bool, E>,
{
self.try_take_while(move |t| ready(f(t)))
}
}