use crate::prelude::*; use nu_protocol::{ReturnSuccess, ReturnValue, Value}; use std::iter::IntoIterator; pub type OutputStream = InputStream; pub struct ActionStream { pub values: Box + Send + Sync>, } impl Iterator for ActionStream { type Item = ReturnValue; fn next(&mut self) -> Option { self.values.next() } } impl ActionStream { pub fn new(values: impl Iterator + Send + Sync + 'static) -> ActionStream { ActionStream { values: Box::new(values), } } pub fn empty() -> ActionStream { ActionStream { values: Box::new(std::iter::empty()), } } pub fn one(item: impl Into) -> ActionStream { let item = item.into(); ActionStream { values: Box::new(std::iter::once(item)), } } pub fn from_input(input: impl Iterator + Send + Sync + 'static) -> ActionStream { ActionStream { values: Box::new(input.map(ReturnSuccess::value)), } } pub fn drain_vec(&mut self) -> Vec { let mut output = vec![]; for x in &mut self.values { output.push(x); } output } } impl From for ActionStream { fn from(input: InputStream) -> ActionStream { ActionStream { values: Box::new(input.into_iter().map(ReturnSuccess::value)), } } } // impl From + Send + Sync + 'static> for OutputStream { // fn from(input: impl Iterator + Send + Sync + 'static) -> OutputStream { // OutputStream { // values: Box::new(input.map(ReturnSuccess::value)), // } // } // } // impl From> for OutputStream { // fn from(input: BoxStream<'static, ReturnValue>) -> OutputStream { // OutputStream { values: input } // } // } impl From> for ActionStream { fn from(input: VecDeque) -> ActionStream { ActionStream { values: Box::new(input.into_iter()), } } } impl From> for ActionStream { fn from(input: VecDeque) -> ActionStream { let stream = input.into_iter().map(ReturnSuccess::value); ActionStream { values: Box::new(stream), } } } impl From> for ActionStream { fn from(input: Vec) -> ActionStream { ActionStream { values: Box::new(input.into_iter()), } } } impl From> for ActionStream { fn from(input: Vec) -> ActionStream { let stream = input.into_iter().map(ReturnSuccess::value); ActionStream { values: Box::new(stream), } } }