1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-08-07 15:20:55 +00:00

add unwrap_or_default() to future TryExt extension

start an OptionFuture extension

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-12-07 06:02:59 +00:00
parent d921b82376
commit aa6d0fcaa7
3 changed files with 38 additions and 0 deletions

View file

@ -0,0 +1,22 @@
#![allow(clippy::wrong_self_convention)]
use futures::{future::OptionFuture, Future, FutureExt};
pub trait OptionExt<T> {
fn is_none_or(self, f: impl FnOnce(&T) -> bool + Send) -> impl Future<Output = bool> + Send;
fn is_some_and(self, f: impl FnOnce(&T) -> bool + Send) -> impl Future<Output = bool> + Send;
}
impl<T, Fut> OptionExt<T> for OptionFuture<Fut>
where
Fut: Future<Output = T> + Send,
{
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))
}
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))
}
}