2019-05-23 07:23:06 +00:00
|
|
|
use crate::prelude::*;
|
|
|
|
|
2019-07-03 20:31:15 +00:00
|
|
|
pub struct InputStream {
|
2019-07-08 16:44:53 +00:00
|
|
|
crate values: BoxStream<'static, Spanned<Value>>,
|
2019-07-03 20:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl InputStream {
|
2019-07-08 16:44:53 +00:00
|
|
|
pub fn into_vec(self) -> impl Future<Output = Vec<Spanned<Value>>> {
|
2019-07-03 20:31:15 +00:00
|
|
|
self.values.collect()
|
|
|
|
}
|
|
|
|
|
2019-08-03 02:17:28 +00:00
|
|
|
pub fn drain_vec(&mut self) -> impl Future<Output = Vec<Spanned<Value>>> {
|
|
|
|
let mut values: BoxStream<'static, Spanned<Value>> = VecDeque::new().boxed();
|
|
|
|
std::mem::swap(&mut values, &mut self.values);
|
|
|
|
|
|
|
|
values.collect()
|
|
|
|
}
|
|
|
|
|
2019-07-08 16:44:53 +00:00
|
|
|
pub fn from_stream(input: impl Stream<Item = Spanned<Value>> + Send + 'static) -> InputStream {
|
2019-07-03 20:31:15 +00:00
|
|
|
InputStream {
|
|
|
|
values: input.boxed(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-09 04:31:26 +00:00
|
|
|
impl From<BoxStream<'static, Spanned<Value>>> for InputStream {
|
|
|
|
fn from(input: BoxStream<'static, Spanned<Value>>) -> InputStream {
|
2019-07-03 20:31:15 +00:00
|
|
|
InputStream { values: input }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-08 16:44:53 +00:00
|
|
|
impl From<VecDeque<Spanned<Value>>> for InputStream {
|
|
|
|
fn from(input: VecDeque<Spanned<Value>>) -> InputStream {
|
2019-07-03 20:31:15 +00:00
|
|
|
InputStream {
|
|
|
|
values: input.boxed(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-09 04:31:26 +00:00
|
|
|
impl From<Vec<Spanned<Value>>> for InputStream {
|
|
|
|
fn from(input: Vec<Spanned<Value>>) -> InputStream {
|
2019-07-03 20:31:15 +00:00
|
|
|
let mut list = VecDeque::default();
|
|
|
|
list.extend(input);
|
|
|
|
|
|
|
|
InputStream {
|
|
|
|
values: list.boxed(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct OutputStream {
|
|
|
|
crate values: BoxStream<'static, ReturnValue>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl OutputStream {
|
2019-08-03 02:17:28 +00:00
|
|
|
pub fn new(values: impl Stream<Item = ReturnValue> + Send + 'static) -> OutputStream {
|
|
|
|
OutputStream {
|
|
|
|
values: values.boxed(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-09 04:31:26 +00:00
|
|
|
pub fn empty() -> OutputStream {
|
|
|
|
let v: VecDeque<ReturnValue> = VecDeque::new();
|
|
|
|
v.into()
|
|
|
|
}
|
|
|
|
|
2019-08-02 19:15:07 +00:00
|
|
|
pub fn one(item: impl Into<ReturnValue>) -> OutputStream {
|
2019-08-03 02:17:28 +00:00
|
|
|
let mut v: VecDeque<ReturnValue> = VecDeque::new();
|
2019-08-02 19:15:07 +00:00
|
|
|
v.push_back(item.into());
|
|
|
|
v.into()
|
|
|
|
}
|
|
|
|
|
2019-07-08 16:44:53 +00:00
|
|
|
pub fn from_input(input: impl Stream<Item = Spanned<Value>> + Send + 'static) -> OutputStream {
|
2019-07-03 20:31:15 +00:00
|
|
|
OutputStream {
|
|
|
|
values: input.map(ReturnSuccess::value).boxed(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-03 02:17:28 +00:00
|
|
|
impl Stream for OutputStream {
|
|
|
|
type Item = ReturnValue;
|
|
|
|
|
|
|
|
fn poll_next(
|
|
|
|
mut self: std::pin::Pin<&mut Self>,
|
|
|
|
cx: &mut std::task::Context<'_>,
|
|
|
|
) -> core::task::Poll<Option<Self::Item>> {
|
|
|
|
Stream::poll_next(std::pin::Pin::new(&mut self.values), cx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-03 20:31:15 +00:00
|
|
|
impl From<InputStream> for OutputStream {
|
|
|
|
fn from(input: InputStream) -> OutputStream {
|
|
|
|
OutputStream {
|
|
|
|
values: input.values.map(ReturnSuccess::value).boxed(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-09 04:31:26 +00:00
|
|
|
impl From<BoxStream<'static, Spanned<Value>>> for OutputStream {
|
|
|
|
fn from(input: BoxStream<'static, Spanned<Value>>) -> OutputStream {
|
2019-07-03 20:31:15 +00:00
|
|
|
OutputStream {
|
|
|
|
values: input.map(ReturnSuccess::value).boxed(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<BoxStream<'static, ReturnValue>> for OutputStream {
|
|
|
|
fn from(input: BoxStream<'static, ReturnValue>) -> OutputStream {
|
|
|
|
OutputStream { values: input }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<VecDeque<ReturnValue>> for OutputStream {
|
|
|
|
fn from(input: VecDeque<ReturnValue>) -> OutputStream {
|
|
|
|
OutputStream {
|
|
|
|
values: input.boxed(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-09 04:31:26 +00:00
|
|
|
impl From<VecDeque<Spanned<Value>>> for OutputStream {
|
|
|
|
fn from(input: VecDeque<Spanned<Value>>) -> OutputStream {
|
|
|
|
OutputStream {
|
|
|
|
values: input
|
|
|
|
.into_iter()
|
|
|
|
.map(|i| ReturnSuccess::value(i))
|
|
|
|
.collect::<VecDeque<ReturnValue>>()
|
|
|
|
.boxed(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-03 20:31:15 +00:00
|
|
|
impl From<Vec<ReturnValue>> for OutputStream {
|
|
|
|
fn from(input: Vec<ReturnValue>) -> OutputStream {
|
|
|
|
let mut list = VecDeque::default();
|
|
|
|
list.extend(input);
|
|
|
|
|
|
|
|
OutputStream {
|
|
|
|
values: list.boxed(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-09 04:31:26 +00:00
|
|
|
impl From<Vec<Spanned<Value>>> for OutputStream {
|
|
|
|
fn from(input: Vec<Spanned<Value>>) -> OutputStream {
|
2019-07-03 20:31:15 +00:00
|
|
|
let mut list = VecDeque::default();
|
|
|
|
list.extend(input.into_iter().map(ReturnSuccess::value));
|
2019-05-23 07:23:06 +00:00
|
|
|
|
2019-07-03 20:31:15 +00:00
|
|
|
OutputStream {
|
|
|
|
values: list.boxed(),
|
|
|
|
}
|
|
|
|
}
|
2019-05-23 07:23:06 +00:00
|
|
|
}
|