Fix up for_in

This commit is contained in:
JT
2021-09-03 14:57:18 +12:00
parent df63490266
commit 750502c870
5 changed files with 38 additions and 27 deletions

View File

@ -3,6 +3,7 @@ use std::{cell::RefCell, collections::HashMap, rc::Rc};
use crate::{ShellError, Value, VarId};
#[derive(Clone)]
pub struct EvaluationContext {
pub engine_state: Rc<RefCell<EngineState>>,
pub stack: Stack,

View File

@ -5,7 +5,7 @@ use crate::{span, BlockId, Span, Type};
use crate::ShellError;
#[derive(Clone)]
pub struct ValueStream(Rc<RefCell<dyn Iterator<Item = Value>>>);
pub struct ValueStream(pub Rc<RefCell<dyn Iterator<Item = Value>>>);
impl ValueStream {
pub fn into_string(self) -> String {
@ -18,6 +18,10 @@ impl ValueStream {
.join(", ".into())
)
}
pub fn from_stream(input: impl Iterator<Item = Value> + 'static) -> ValueStream {
ValueStream(Rc::new(RefCell::new(input)))
}
}
impl Debug for ValueStream {
@ -41,9 +45,12 @@ pub trait IntoValueStream {
fn into_value_stream(self) -> ValueStream;
}
impl IntoValueStream for Vec<Value> {
impl<T> IntoValueStream for T
where
T: Iterator<Item = Value> + 'static,
{
fn into_value_stream(self) -> ValueStream {
ValueStream(Rc::new(RefCell::new(self.into_iter())))
ValueStream::from_stream(self)
}
}