Make FromValue take owned Values (#10900)

# Description
Changes `FromValue` to take owned `Value`s instead of borrowed `Value`s.
This eliminates some unnecessary clones (e.g., in `call_ext.rs`).

# User-Facing Changes
Breaking API change for `nu_protocol`.
This commit is contained in:
Ian Manske
2023-10-31 18:47:00 +00:00
committed by GitHub
parent 1c52b112c8
commit 15c22db8f4
9 changed files with 102 additions and 116 deletions

View File

@ -1,15 +1,16 @@
use nu_protocol::{FromValue, ShellError, Value};
pub fn extract_strings(value: Value) -> Result<Vec<String>, ShellError> {
let span = value.span();
match (
<String as FromValue>::from_value(&value),
<Vec<String> as FromValue>::from_value(&value),
<String as FromValue>::from_value(value.clone()),
<Vec<String> as FromValue>::from_value(value),
) {
(Ok(col), Err(_)) => Ok(vec![col]),
(Err(_), Ok(cols)) => Ok(cols),
_ => Err(ShellError::IncompatibleParametersSingle {
msg: "Expected a string or list of strings".into(),
span: value.span(),
span,
}),
}
}