-
Notifications
You must be signed in to change notification settings - Fork 671
Open
Description
Can you add some function like this?
use std::future::Future;
pub trait AsyncThenSome {
fn async_then_some<F>(self, future: F) -> impl Future<Output = Option<F::Output>> + Send
where
F: Future + Send,
F::Output: Send;
}
impl AsyncThenSome for bool {
async fn async_then_some<F>(self, future: F) -> Option<F::Output>
where
F: Future + Send,
F::Output: Send,
{
if !self { None } else { Some(future.await) }
}
}
pub trait AsyncMap<T> {
fn async_map<F, R>(self, func: F) -> impl Future<Output = Option<R>>
where
F: AsyncFn(T) -> R;
}
impl<T> AsyncMap<T> for Option<T> {
async fn async_map<F, R>(self, func: F) -> Option<R>
where
F: AsyncFn(T) -> R,
{
match self {
None => None,
Some(v) => Some(func(v).await),
}
}
}Metadata
Metadata
Assignees
Labels
No labels