use futures::{FutureExt, Stream, future::OptionFuture}; use super::IterStream; pub trait OptionExt where Fut: Future + Send, U: Send, { fn map_async(self, f: F) -> OptionFuture where F: FnOnce(T) -> Fut; #[inline] fn map_stream(self, f: F) -> impl Stream + Send where F: FnOnce(T) -> Fut, Self: Sized, { self.map_async(f) .map(Option::into_iter) .map(IterStream::stream) .flatten_stream() } } impl OptionExt for Option where Fut: Future + Send, U: Send, { #[inline] fn map_async(self, f: F) -> OptionFuture where F: FnOnce(T) -> Fut, { self.map(f).into() } }