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