refactor: ensure range is bounded (#15429)

No linked issue, it's a follow-up of 2 PRs I recently made to improve
some math commands. (#15319)

# Description
Small refactor to simplify the code. It was suggested in the comments of
my previous PR.

# User-Facing Changes
None

# Tests + Formatting
Tests, fmt and clippy OK

# After Submitting
Nothing more required
This commit is contained in:
Loïc Riegel
2025-03-27 14:25:55 +01:00
committed by GitHub
parent 07be33c119
commit 5d32cd2c40
8 changed files with 30 additions and 71 deletions

View File

@@ -1,6 +1,5 @@
use crate::math::utils::ensure_bounded;
use nu_engine::command_prelude::*;
use nu_protocol::Range;
#[derive(Clone)]
pub struct MathSqrt;
@@ -56,10 +55,7 @@ impl Command for MathSqrt {
..,
) = input
{
match &**val {
Range::IntRange(range) => ensure_bounded(range.end(), internal_span, head)?,
Range::FloatRange(range) => ensure_bounded(range.end(), internal_span, head)?,
}
ensure_bounded(val.as_ref(), internal_span, head)?;
}
input.map(move |value| operate(value, head), engine_state.signals())
}
@@ -83,10 +79,7 @@ impl Command for MathSqrt {
..,
) = input
{
match &**val {
Range::IntRange(range) => ensure_bounded(range.end(), internal_span, head)?,
Range::FloatRange(range) => ensure_bounded(range.end(), internal_span, head)?,
}
ensure_bounded(val.as_ref(), internal_span, head)?;
}
input.map(
move |value| operate(value, head),