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

@ -157,7 +157,7 @@ fn get_cellpath_columns(keep_cols: Vec<String>, span: Span) -> Vec<CellPath> {
let mut output = vec![];
for keep_col in keep_cols {
let val = Value::string(keep_col, span);
let cell_path = match CellPath::from_value(&val) {
let cell_path = match CellPath::from_value(val) {
Ok(v) => v,
Err(_) => return vec![],
};

View File

@ -3,8 +3,8 @@ use nu_engine::CallExt;
use nu_protocol::ast::{Call, RangeInclusion};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Category, Example, FromValue, IntoInterruptiblePipelineData, PipelineData, PipelineIterator,
Range, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
Category, Example, IntoInterruptiblePipelineData, PipelineData, PipelineIterator, Range,
ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
};
#[derive(Clone)]
@ -185,9 +185,7 @@ fn extract_int_or_range(
let value = call.req::<Value>(engine_state, stack, 0)?;
let int_opt = value.as_int().map(Either::Left).ok();
let range_opt: Result<nu_protocol::Range, ShellError> = FromValue::from_value(&value);
let range_opt = range_opt.map(Either::Right).ok();
let range_opt = value.as_range().map(|r| Either::Right(r.clone())).ok();
int_opt
.or(range_opt)

View File

@ -122,7 +122,7 @@ fn insert(
// Replace is a block, so set it up and run it instead of using it as the replacement
if replacement.as_block().is_ok() {
let capture_block: Closure = FromValue::from_value(&replacement)?;
let capture_block = Closure::from_value(replacement)?;
let block = engine_state.get_block(capture_block.block_id).clone();
let mut stack = stack.captures_to_stack(&capture_block.captures);

View File

@ -119,7 +119,7 @@ fn update(
// Replace is a block, so set it up and run it instead of using it as the replacement
if replacement.as_block().is_ok() {
let capture_block: Closure = FromValue::from_value(&replacement)?;
let capture_block = Closure::from_value(replacement)?;
let block = engine_state.get_block(capture_block.block_id).clone();
let mut stack = stack.captures_to_stack(&capture_block.captures);

View File

@ -141,7 +141,7 @@ fn upsert(
// Replace is a block, so set it up and run it instead of using it as the replacement
if replacement.as_block().is_ok() {
let capture_block: Closure = FromValue::from_value(&replacement)?;
let capture_block = Closure::from_value(replacement)?;
let block = engine_state.get_block(capture_block.block_id).clone();
let mut stack = stack.captures_to_stack(&capture_block.captures);