Implement Display for CellPath (#11023)

# Description
Because `CellPath::into_string` takes a borrowed `self`, I renamed it to
`to_string` to follow Rust [API
guidelines](https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv).
This then triggered the clippy lint
[inherent_to_string](https://rust-lang.github.io/rust-clippy/master/index.html#/inherent_to_string),
which is... correct! The current `CellPath::into_string` is being used
as if it were the `Display` implementation for `CellPath`.

# User-Facing Changes
Breaking API change for `nu-protocol`, since `CellPath::into_string` was
removed.
This commit is contained in:
Ian Manske
2023-11-10 20:12:51 +00:00
committed by GitHub
parent 523d0bca16
commit 93096a07aa
9 changed files with 29 additions and 32 deletions

View File

@ -262,7 +262,7 @@ fn nu_value_to_string(value: Value, separator: &str) -> String {
Value::Nothing { .. } => String::new(),
Value::Error { error, .. } => format!("{error:?}"),
Value::Binary { val, .. } => format!("{val:?}"),
Value::CellPath { val, .. } => val.into_string(),
Value::CellPath { val, .. } => val.to_string(),
Value::CustomValue { val, .. } => val.value_string(),
Value::MatchPattern { val, .. } => format!("{:?}", val),
}

View File

@ -257,7 +257,7 @@ pub fn debug_string_without_formatting(value: &Value) -> String {
Value::Nothing { .. } => String::new(),
Value::Error { error, .. } => format!("{error:?}"),
Value::Binary { val, .. } => format!("{val:?}"),
Value::CellPath { val, .. } => val.into_string(),
Value::CellPath { val, .. } => val.to_string(),
Value::CustomValue { val, .. } => val.value_string(),
Value::MatchPattern { val, .. } => format!("{:?}", val),
}

View File

@ -163,7 +163,7 @@ fn flat_value(columns: &[CellPath], item: Value, all: bool) -> Vec<Value> {
let mut inner_table = None;
for (column_index, (column, value)) in val.into_iter().enumerate() {
let column_requested = columns.iter().find(|c| c.into_string() == column);
let column_requested = columns.iter().find(|c| c.to_string() == column);
let need_flatten = { columns.is_empty() || column_requested.is_some() };
let span = value.span();

View File

@ -254,7 +254,7 @@ fn select(
//FIXME: improve implementation to not clone
match input_val.clone().follow_cell_path(&path.members, false) {
Ok(fetcher) => {
record.push(path.into_string().replace('.', "_"), fetcher);
record.push(path.to_string().replace('.', "_"), fetcher);
if !columns_with_value.contains(&path) {
columns_with_value.push(path);
}
@ -284,7 +284,7 @@ fn select(
// FIXME: remove clone
match v.clone().follow_cell_path(&cell_path.members, false) {
Ok(result) => {
record.push(cell_path.into_string().replace('.', "_"), result);
record.push(cell_path.to_string().replace('.', "_"), result);
}
Err(e) => return Err(e),
}
@ -309,7 +309,7 @@ fn select(
//FIXME: improve implementation to not clone
match x.clone().follow_cell_path(&path.members, false) {
Ok(value) => {
record.push(path.into_string().replace('.', "_"), value);
record.push(path.to_string().replace('.', "_"), value);
}
Err(e) => return Err(e),
}

View File

@ -146,7 +146,7 @@ fn local_into_string(value: Value, separator: &str, config: &Config) -> String {
Value::Nothing { .. } => String::new(),
Value::Error { error, .. } => format!("{error:?}"),
Value::Binary { val, .. } => format!("{val:?}"),
Value::CellPath { val, .. } => val.into_string(),
Value::CellPath { val, .. } => val.to_string(),
Value::CustomValue { val, .. } => val.value_string(),
Value::MatchPattern { val, .. } => format!("{:?}", val),
}