mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 12:46:00 +02:00
Spanned Value step 1: span all value cases (#10042)
# Description This doesn't really do much that the user could see, but it helps get us ready to do the steps of the refactor to split the span off of Value, so that values can be spanless. This allows us to have top-level values that can hold both a Value and a Span, without requiring that all values have them. We expect to see significant memory reduction by removing so many unnecessary spans from values. For example, a table of 100,000 rows and 5 columns would have a savings of ~8megs in just spans that are almost always duplicated. # User-Facing Changes Nothing yet # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
This commit is contained in:
@ -99,12 +99,12 @@ fn action(
|
||||
Some(config_character_set.span),
|
||||
None,
|
||||
Vec::new(),
|
||||
))}
|
||||
)), span:config_character_set.span}
|
||||
};
|
||||
match input {
|
||||
// Propagate existing errors.
|
||||
Value::Error { .. } => input.clone(),
|
||||
Value::Binary { val, .. } => match base64_config.action_type {
|
||||
Value::Binary { val, span } => match base64_config.action_type {
|
||||
ActionType::Encode => {
|
||||
let mut enc_vec = Vec::new();
|
||||
enc_vec.resize(val.len() * 4 / 3 + 4, 0);
|
||||
@ -115,10 +115,11 @@ fn action(
|
||||
error: Box::new(ShellError::GenericError(
|
||||
"Error encoding data".into(),
|
||||
err.to_string(),
|
||||
Some(Span::unknown()),
|
||||
Some(*span),
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
span: *span,
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -131,8 +132,9 @@ fn action(
|
||||
"value originates from here".into(),
|
||||
command_span,
|
||||
// This line requires the Value::Error {} match above.
|
||||
input.expect_span(),
|
||||
input.span(),
|
||||
)),
|
||||
span: command_span,
|
||||
},
|
||||
},
|
||||
Value::String {
|
||||
@ -167,6 +169,7 @@ fn action(
|
||||
Some("consider using the `--binary` flag".to_owned()),
|
||||
Vec::new(),
|
||||
)),
|
||||
span: *value_span,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -182,6 +185,7 @@ fn action(
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
span: command_span,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -190,8 +194,9 @@ fn action(
|
||||
other => Value::Error {
|
||||
error: Box::new(ShellError::TypeMismatch {
|
||||
err_message: format!("string or binary, not {}", other.get_type()),
|
||||
span: other.span().unwrap_or(command_span),
|
||||
span: other.span(),
|
||||
}),
|
||||
span: other.span(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -77,12 +77,12 @@ documentation link at https://docs.rs/encoding_rs/latest/encoding_rs/#statics"#
|
||||
PipelineData::Value(v, ..) => match v {
|
||||
Value::Binary { val: bytes, .. } => super::encoding::decode(head, encoding, &bytes)
|
||||
.map(|val| val.into_pipeline_data()),
|
||||
Value::Error { error } => Err(*error),
|
||||
Value::Error { error, .. } => Err(*error),
|
||||
_ => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "binary".into(),
|
||||
wrong_type: v.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: v.expect_span(),
|
||||
src_span: v.span(),
|
||||
}),
|
||||
},
|
||||
// This should be more precise, but due to difficulties in getting spans
|
||||
|
@ -100,12 +100,12 @@ documentation link at https://docs.rs/encoding_rs/latest/encoding_rs/#statics"#
|
||||
super::encoding::encode(head, encoding, &s, span, ignore_errors)
|
||||
.map(|val| val.into_pipeline_data())
|
||||
}
|
||||
Value::Error { error } => Err(*error),
|
||||
Value::Error { error, .. } => Err(*error),
|
||||
_ => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: v.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: v.expect_span(),
|
||||
src_span: v.span(),
|
||||
}),
|
||||
},
|
||||
// This should be more precise, but due to difficulties in getting spans
|
||||
|
Reference in New Issue
Block a user