mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 05:04:40 +02:00
Replace &Span
with Span
since Span
is Copy
(#9770)
# Description `Span` is `Copy`, so we probably should not be passing references of `Span` around. This PR replaces all instances of `&Span` with `Span`, copying spans where necessary. # User-Facing Changes This alters some public functions to take `Span` instead of `&Span` as input. Namely, `EngineState::get_span_contents`, `nu_protocol::extract_value`, a bunch of the math commands, and `Gstat::gstat`.
This commit is contained in:
@ -47,7 +47,7 @@ pub fn execute_json_query(
|
||||
let json_str = val.json();
|
||||
Ok(Value::string(json_str, call.head))
|
||||
} else {
|
||||
Ok(convert_gjson_value_to_nu_value(&val, &call.head))
|
||||
Ok(convert_gjson_value_to_nu_value(&val, call.head))
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ fn query_contains_modifiers(query: &str) -> bool {
|
||||
// @join: Joins multiple objects into a single object.
|
||||
}
|
||||
|
||||
fn convert_gjson_value_to_nu_value(v: &gjValue, span: &Span) -> Value {
|
||||
fn convert_gjson_value_to_nu_value(v: &gjValue, span: Span) -> Value {
|
||||
match v.kind() {
|
||||
gjson::Kind::Array => {
|
||||
let mut vals = vec![];
|
||||
@ -79,20 +79,20 @@ fn convert_gjson_value_to_nu_value(v: &gjValue, span: &Span) -> Value {
|
||||
true
|
||||
});
|
||||
|
||||
Value::List { vals, span: *span }
|
||||
Value::List { vals, span }
|
||||
}
|
||||
gjson::Kind::Null => Value::nothing(*span),
|
||||
gjson::Kind::False => Value::bool(false, *span),
|
||||
gjson::Kind::Null => Value::nothing(span),
|
||||
gjson::Kind::False => Value::bool(false, span),
|
||||
gjson::Kind::Number => {
|
||||
let str_value = v.str();
|
||||
if str_value.contains('.') {
|
||||
Value::float(v.f64(), *span)
|
||||
Value::float(v.f64(), span)
|
||||
} else {
|
||||
Value::int(v.i64(), *span)
|
||||
Value::int(v.i64(), span)
|
||||
}
|
||||
}
|
||||
gjson::Kind::String => Value::string(v.str(), *span),
|
||||
gjson::Kind::True => Value::bool(true, *span),
|
||||
gjson::Kind::String => Value::string(v.str(), span),
|
||||
gjson::Kind::True => Value::bool(true, span),
|
||||
gjson::Kind::Object => {
|
||||
let mut cols = vec![];
|
||||
let mut vals = vec![];
|
||||
@ -101,11 +101,7 @@ fn convert_gjson_value_to_nu_value(v: &gjValue, span: &Span) -> Value {
|
||||
vals.push(convert_gjson_value_to_nu_value(&v, span));
|
||||
true
|
||||
});
|
||||
Value::Record {
|
||||
cols,
|
||||
vals,
|
||||
span: *span,
|
||||
}
|
||||
Value::Record { cols, vals, span }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ pub fn execute_xpath_query(
|
||||
query: Option<Spanned<String>>,
|
||||
) -> Result<Value, LabeledError> {
|
||||
let (query_string, span) = match &query {
|
||||
Some(v) => (&v.item, &v.span),
|
||||
Some(v) => (&v.item, v.span),
|
||||
None => {
|
||||
return Err(LabeledError {
|
||||
msg: "problem with input data".to_string(),
|
||||
@ -101,20 +101,20 @@ pub fn execute_xpath_query(
|
||||
}
|
||||
}
|
||||
|
||||
fn build_xpath(xpath_str: &str, span: &Span) -> Result<sxd_xpath::XPath, LabeledError> {
|
||||
fn build_xpath(xpath_str: &str, span: Span) -> Result<sxd_xpath::XPath, LabeledError> {
|
||||
let factory = Factory::new();
|
||||
|
||||
if let Ok(xpath) = factory.build(xpath_str) {
|
||||
xpath.ok_or_else(|| LabeledError {
|
||||
label: "invalid xpath query".to_string(),
|
||||
msg: "invalid xpath query".to_string(),
|
||||
span: Some(*span),
|
||||
span: Some(span),
|
||||
})
|
||||
} else {
|
||||
Err(LabeledError {
|
||||
label: "expected valid xpath query".to_string(),
|
||||
msg: "expected valid xpath query".to_string(),
|
||||
span: Some(*span),
|
||||
span: Some(span),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user