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

@ -238,7 +238,7 @@ impl EvaluatedCall {
/// ```
pub fn get_flag<T: FromValue>(&self, name: &str) -> Result<Option<T>, ShellError> {
if let Some(value) = self.get_flag_value(name) {
FromValue::from_value(&value).map(Some)
FromValue::from_value(value).map(Some)
} else {
Ok(None)
}
@ -272,7 +272,7 @@ impl EvaluatedCall {
self.positional
.iter()
.skip(starting_pos)
.map(|value| FromValue::from_value(value))
.map(|value| FromValue::from_value(value.clone()))
.collect()
}
@ -283,7 +283,7 @@ impl EvaluatedCall {
/// or an error that can be passed back to the shell on error.
pub fn opt<T: FromValue>(&self, pos: usize) -> Result<Option<T>, ShellError> {
if let Some(value) = self.nth(pos) {
FromValue::from_value(&value).map(Some)
FromValue::from_value(value).map(Some)
} else {
Ok(None)
}
@ -296,7 +296,7 @@ impl EvaluatedCall {
/// be passed back to the shell.
pub fn req<T: FromValue>(&self, pos: usize) -> Result<T, ShellError> {
if let Some(value) = self.nth(pos) {
FromValue::from_value(&value)
FromValue::from_value(value)
} else if self.positional.is_empty() {
Err(ShellError::AccessEmptyContent { span: self.head })
} else {