nushell/src/commands/to_array.rs

40 lines
996 B
Rust
Raw Normal View History

2019-05-13 23:00:25 +02:00
use crate::errors::ShellError;
use crate::object::process::Process;
2019-05-16 00:23:36 +02:00
use crate::object::{dir_entry_dict, Value};
2019-05-13 23:00:25 +02:00
use crate::prelude::*;
use crate::Args;
use derive_new::new;
use std::path::{Path, PathBuf};
use sysinfo::SystemExt;
#[derive(new)]
pub struct ToArrayBlueprint;
impl crate::CommandBlueprint for ToArrayBlueprint {
fn create(
&self,
args: Vec<Value>,
host: &dyn Host,
env: &mut Environment,
) -> 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
}