mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 11:35:43 +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:
@ -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 {
|
||||
|
Reference in New Issue
Block a user