async_std/option/
from_stream.rs1use std::pin::Pin;
2
3use crate::prelude::*;
4use crate::stream::{FromStream, IntoStream};
5use std::convert::identity;
6
7impl<T: Send, V> FromStream<Option<T>> for Option<V>
8where
9 V: FromStream<T>,
10{
11 #[inline]
15 fn from_stream<'a, S: IntoStream<Item = Option<T>> + 'a>(
16 stream: S,
17 ) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
18 where
19 <S as IntoStream>::IntoStream: Send,
20 {
21 let stream = stream.into_stream();
22
23 Box::pin(async move {
24 let mut found_none = false;
27 let out: V = stream
28 .take_while(|elem| {
29 elem.is_some() || {
30 found_none = true;
31 false
33 }
34 })
35 .filter_map(identity)
36 .collect()
37 .await;
38
39 if found_none { None } else { Some(out) }
40 })
41 }
42}