nushell/crates/nu-engine/src/column.rs
Maxim Zhiburt a3dce8ff19
table -e Fix stackoverflow (cause endless empty list) (#6847)
Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2022-10-22 11:52:32 -05:00

41 lines
898 B
Rust

use nu_protocol::Value;
use std::collections::HashSet;
pub fn get_columns<'a>(input: impl IntoIterator<Item = &'a Value>) -> Vec<String> {
let mut columns = vec![];
for item in input {
if let Value::Record { cols, vals: _, .. } = item {
for col in cols {
if !columns.contains(col) {
columns.push(col.to_string());
}
}
} else {
return vec![];
}
}
columns
}
/*
* Check to see if any of the columns inside the input
* does not exist in a vec of columns
*/
pub fn column_does_not_exist(inputs: Vec<String>, columns: Vec<String>) -> bool {
let mut set = HashSet::new();
for column in columns {
set.insert(column);
}
for input in &inputs {
if set.contains(input) {
continue;
}
return true;
}
false
}