use std::pin::Pin;
use crate::prelude::*;
use crate::stream::{FromStream, IntoStream};
impl<T, V> FromStream<Option<T>> for Option<V>
where
V: FromStream<T>,
{
#[inline]
fn from_stream<'a, S: IntoStream<Item = Option<T>> + 'a>(
stream: S,
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {
let mut found_error = false;
let out: V = stream
.scan((), |_, elem| {
match elem {
Some(elem) => Some(elem),
None => {
found_error = true;
None
}
}
})
.collect()
.await;
if found_error { None } else { Some(out) }
})
}
}