2019-05-13 23:00:25 +02:00
|
|
|
use crate::errors::ShellError;
|
2019-05-16 00:58:44 +02:00
|
|
|
use crate::object::Value;
|
2019-05-13 23:00:25 +02:00
|
|
|
use crate::prelude::*;
|
|
|
|
use derive_new::new;
|
|
|
|
|
|
|
|
#[derive(new)]
|
|
|
|
pub struct ToArrayBlueprint;
|
|
|
|
|
|
|
|
impl crate::CommandBlueprint for ToArrayBlueprint {
|
|
|
|
fn create(
|
|
|
|
&self,
|
2019-05-16 00:58:44 +02:00
|
|
|
_args: Vec<Value>,
|
|
|
|
_host: &dyn Host,
|
|
|
|
_env: &mut Environment,
|
2019-05-13 23:00:25 +02:00
|
|
|
) -> Result<Box<dyn Command>, ShellError> {
|
|
|
|
Ok(Box::new(ToArray))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(new)]
|
|
|
|
pub struct ToArray;
|
|
|
|
|
|
|
|
impl crate::Command for ToArray {
|
|
|
|
fn run(&mut self, stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError> {
|
|
|
|
let out = stream.into_iter().collect();
|
|
|
|
Ok(ReturnValue::single(Value::List(out)))
|
|
|
|
}
|
|
|
|
}
|
2019-05-15 18:12:38 +02:00
|
|
|
|
|
|
|
crate fn to_array(stream: VecDeque<Value>) -> VecDeque<Value> {
|
|
|
|
let out = Value::List(stream.into_iter().collect());
|
|
|
|
let mut stream = VecDeque::new();
|
|
|
|
stream.push_back(out);
|
|
|
|
stream
|
|
|
|
}
|