mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 13:46:03 +02:00
Make FromValue
take owned Value
s (#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:
@ -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,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user