Move Value to helpers, separate span call (#10121)

# Description

As part of the refactor to split spans off of Value, this moves to using
helper functions to create values, and using `.span()` instead of
matching span out of Value directly.

Hoping to get a few more helping hands to finish this, as there are a
lot of commands to update :)

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `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.
-->

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
Co-authored-by: WindSoilder <windsoilder@outlook.com>
This commit is contained in:
JT
2023-09-04 02:27:29 +12:00
committed by GitHub
parent af79eb2943
commit 6cdfee3573
372 changed files with 5811 additions and 7448 deletions

View File

@ -84,13 +84,7 @@ fn bool(
let mut rng = thread_rng();
let bool_result: bool = rng.gen_bool(probability);
Ok(PipelineData::Value(
Value::Bool {
val: bool_result,
span,
},
None,
))
Ok(PipelineData::Value(Value::bool(bool_result, span), None))
}
#[cfg(test)]

View File

@ -79,10 +79,7 @@ fn chars(
.collect::<String>();
Ok(PipelineData::Value(
Value::String {
val: random_string,
span,
},
Value::string(random_string, span),
None,
))
}

View File

@ -94,10 +94,7 @@ fn decimal(
span,
}),
Some(Ordering::Equal) => Ok(PipelineData::Value(
Value::Float {
val: min,
span: Span::new(64, 64),
},
Value::float(min, Span::new(64, 64)),
None,
)),
_ => {
@ -105,10 +102,7 @@ fn decimal(
let result: f64 = thread_rng.gen_range(min..max);
Ok(PipelineData::Value(
Value::Float {
val: result,
span: Span::new(64, 64),
},
Value::float(result, Span::new(64, 64)),
None,
))
}

View File

@ -79,10 +79,7 @@ fn dice(
let iter = (0..dice).map(move |_| {
let mut thread_rng = thread_rng();
Value::Int {
val: thread_rng.gen_range(1..sides + 1) as i64,
span,
}
Value::int(thread_rng.gen_range(1..sides + 1) as i64, span)
});
Ok(PipelineData::ListStream(

View File

@ -93,12 +93,12 @@ fn integer(
right_flank: max.to_string(),
span,
}),
Some(Ordering::Equal) => Ok(PipelineData::Value(Value::Int { val: min, span }, None)),
Some(Ordering::Equal) => Ok(PipelineData::Value(Value::int(min, span), None)),
_ => {
let mut thread_rng = thread_rng();
let result: i64 = thread_rng.gen_range(min..=max);
Ok(PipelineData::Value(Value::Int { val: result, span }, None))
Ok(PipelineData::Value(Value::int(result, span), None))
}
}
}

View File

@ -38,16 +38,16 @@ impl Command for RandomCommand {
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
Ok(Value::String {
val: get_full_help(
Ok(Value::string(
get_full_help(
&RandomCommand.signature(),
&RandomCommand.examples(),
engine_state,
stack,
self.is_parser_keyword(),
),
span: call.head,
}
call.head,
)
.into_pipeline_data())
}
}

View File

@ -49,10 +49,7 @@ fn uuid(call: &Call) -> Result<PipelineData, ShellError> {
let span = call.head;
let uuid_4 = Uuid::new_v4().hyphenated().to_string();
Ok(PipelineData::Value(
Value::String { val: uuid_4, span },
None,
))
Ok(PipelineData::Value(Value::string(uuid_4, span), None))
}
#[cfg(test)]