mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Use Record
's public API in a bunch of places (#10927)
# Description Since #10841 the goal is to remove the implementation details of `Record` outside of core operations. To this end use Record iterators and map-like accessors in a bunch of places. In this PR I try to collect the boring cases where I don't expect any dramatic performance impacts or don't have doubts about the correctness afterwards - Use checked record construction in `nu_plugin_example` - Use `Record::into_iter` in `columns` - Use `Record` iterators in `headers` cmd - Use explicit record iterators in `split-by` - Use `Record::into_iter` in variable completions - Use `Record::values` iterator in `into sqlite` - Use `Record::iter_mut` for-loop in `default` - Change `nu_engine::nonexistent_column` to use iterator - Use `Record::columns` iter in `nu-cmd-base` - Use `Record::get_index` in `nu-command/network/http` - Use `Record.insert()` in `merge` - Refactor `move` to use encapsulated record API - Use `Record.insert()` in `explore` - Use proper `Record` API in `explore` - Remove defensiveness around record in `explore` - Use encapsulated record API in more `nu-command`s # User-Facing Changes None intentional # Tests + Formatting (-)
This commit is contained in:
committed by
GitHub
parent
b03ef56bcb
commit
edbf3aaccb
@ -3,8 +3,8 @@ use nu_engine::CallExt;
|
||||
use nu_protocol::{
|
||||
ast::{Call, CellPath},
|
||||
engine::{Command, EngineState, Stack},
|
||||
Category, Example, PipelineData, Record, ShellError, Signature, Span, Spanned, SyntaxShape,
|
||||
Type, Value,
|
||||
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type,
|
||||
Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -181,15 +181,12 @@ fn action(input: &Value, arg: &Arguments, head: Span) -> Value {
|
||||
match mode {
|
||||
ActionMode::Global => match other {
|
||||
Value::Record { val: record, .. } => {
|
||||
let new_vals = record.vals.iter().map(|v| action(v, arg, head)).collect();
|
||||
let new_record = record
|
||||
.iter()
|
||||
.map(|(k, v)| (k.clone(), action(v, arg, head)))
|
||||
.collect();
|
||||
|
||||
Value::record(
|
||||
Record {
|
||||
cols: record.cols.to_vec(),
|
||||
vals: new_vals,
|
||||
},
|
||||
span,
|
||||
)
|
||||
Value::record(new_record, span)
|
||||
}
|
||||
Value::List { vals, .. } => {
|
||||
let new_vals = vals.iter().map(|v| action(v, arg, head)).collect();
|
||||
|
Reference in New Issue
Block a user