mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-06-26 23:36:36 +02:00
25 lines
721 B
Rust
25 lines
721 B
Rust
#![allow(clippy::wrong_self_convention)]
|
|
|
|
use futures::{Future, FutureExt, future::OptionFuture};
|
|
|
|
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,
|
|
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))
|
|
}
|
|
}
|