mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 04:45:04 +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:
@ -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![],
|
||||
};
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user