abstract and encapsulate the awkward OptionFuture into Stream pattern

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-04-04 02:39:40 +00:00
parent 532dfd004d
commit bb8320a691
4 changed files with 35 additions and 40 deletions

View File

@@ -11,11 +11,14 @@ pub trait OptionExt<T> {
impl<T, Fut> OptionExt<T> for OptionFuture<Fut>
where
Fut: Future<Output = T> + Send,
T: Send,
{
#[inline]
fn is_none_or(self, f: impl FnOnce(&T) -> bool + Send) -> impl Future<Output = bool> + Send {
self.map(|o| o.as_ref().is_none_or(f))
}
#[inline]
fn is_some_and(self, f: impl FnOnce(&T) -> bool + Send) -> impl Future<Output = bool> + Send {
self.map(|o| o.as_ref().is_some_and(f))
}