mirror of
https://github.com/nushell/nushell.git
synced 2025-05-24 00:21:17 +00:00
# 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`.
17 lines
532 B
Rust
17 lines
532 B
Rust
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.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,
|
|
}),
|
|
}
|
|
}
|