-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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`.
- Loading branch information
Showing
9 changed files
with
102 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.