Use record API in more parts of nu-protocol (#10928)

# Description

This is pretty complementary/orthogonal to @IanManske 's changes to
`Value` cellpath accessors in:
- #10925
- to a lesser extent #10926

## Steps
- Use `R.remove` in `Value.remove_data_at_cell_path`
- Pretty sound after #10875 (tests mentioned in commit message have been
removed by that)
- Update `did_you_mean` helper to use iterator
- Change `Value::columns` to return iterator
  - This is not a place of honor
- Use `Record::get` in `Value::get_data_by_key`
# User-Facing Changes
None intentional, potential edge cases on duplicated columns could
change (considered undefined behavior)

# Tests + Formatting
(-)
This commit is contained in:
Stefan Holderbach
2023-11-08 23:03:08 +01:00
committed by GitHub
parent 44c0db46e1
commit 92503e6571
6 changed files with 22 additions and 38 deletions

View File

@ -99,7 +99,7 @@ impl Iterator for UpdateCellIterator {
match self.input.next() {
Some(val) => {
if let Some(ref cols) = self.columns {
if !val.columns().iter().any(|c| cols.contains(c)) {
if !val.columns().any(|c| cols.contains(c)) {
return Some(val);
}
}

View File

@ -190,7 +190,7 @@ pub fn value_to_string(
Value::Int { val, .. } => Ok(format!("{}", *val)),
Value::List { vals, .. } => {
let headers = get_columns(vals);
if !headers.is_empty() && vals.iter().all(|x| x.columns() == headers) {
if !headers.is_empty() && vals.iter().all(|x| x.columns().eq(headers.iter())) {
// Table output
let headers: Vec<String> = headers
.iter()

View File

@ -257,7 +257,7 @@ fn convert_to_list(
let mut iter = iter.into_iter().peekable();
if let Some(first) = iter.peek() {
let mut headers = first.columns().to_vec();
let mut headers: Vec<String> = first.columns().cloned().collect();
if !headers.is_empty() {
headers.insert(0, "#".into());