mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 14:36:08 +02:00
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:
@ -1,6 +1,7 @@
|
||||
//! A Range is an iterator over integers or floats.
|
||||
|
||||
use crate::{ast::RangeInclusion, ShellError, Signals, Span, Value};
|
||||
use core::ops::Bound;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{cmp::Ordering, fmt::Display};
|
||||
|
||||
@ -631,6 +632,13 @@ impl Range {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_bounded(&self) -> bool {
|
||||
match self {
|
||||
Range::IntRange(range) => range.end() != Bound::<i64>::Unbounded,
|
||||
Range::FloatRange(range) => range.end() != Bound::<f64>::Unbounded,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_range_iter(self, span: Span, signals: Signals) -> Iter {
|
||||
match self {
|
||||
Range::IntRange(range) => Iter::IntIter(range.into_range_iter(signals), span),
|
||||
|
Reference in New Issue
Block a user