use crate::prelude::*; pub struct InputStream { crate values: BoxStream<'static, Spanned>, } impl InputStream { pub fn into_vec(self) -> impl Future>> { self.values.collect() } pub fn from_stream(input: impl Stream> + Send + 'static) -> InputStream { InputStream { values: input.boxed(), } } } impl From>> for InputStream { fn from(input: BoxStream<'static, Spanned>) -> InputStream { InputStream { values: input } } } impl From>> for InputStream { fn from(input: VecDeque>) -> InputStream { InputStream { values: input.boxed(), } } } impl From>> for InputStream { fn from(input: Vec>) -> InputStream { let mut list = VecDeque::default(); list.extend(input); InputStream { values: list.boxed(), } } } pub struct OutputStream { crate values: BoxStream<'static, ReturnValue>, } impl OutputStream { #[allow(unused)] pub fn empty() -> OutputStream { let v: VecDeque = VecDeque::new(); v.into() } pub fn from_input(input: impl Stream> + Send + 'static) -> OutputStream { OutputStream { values: input.map(ReturnSuccess::value).boxed(), } } } impl From for OutputStream { fn from(input: InputStream) -> OutputStream { OutputStream { values: input.values.map(ReturnSuccess::value).boxed(), } } } impl From>> for OutputStream { fn from(input: BoxStream<'static, Spanned>) -> OutputStream { OutputStream { values: input.map(ReturnSuccess::value).boxed(), } } } impl From> for OutputStream { fn from(input: BoxStream<'static, ReturnValue>) -> OutputStream { OutputStream { values: input } } } impl From> for OutputStream { fn from(input: VecDeque) -> OutputStream { OutputStream { values: input.boxed(), } } } impl From>> for OutputStream { fn from(input: VecDeque>) -> OutputStream { OutputStream { values: input .into_iter() .map(|i| ReturnSuccess::value(i)) .collect::>() .boxed(), } } } impl From> for OutputStream { fn from(input: Vec) -> OutputStream { let mut list = VecDeque::default(); list.extend(input); OutputStream { values: list.boxed(), } } } impl From>> for OutputStream { fn from(input: Vec>) -> OutputStream { let mut list = VecDeque::default(); list.extend(input.into_iter().map(ReturnSuccess::value)); OutputStream { values: list.boxed(), } } }