diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2018-02-10 16:32:05 -0800 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2018-02-10 16:32:05 -0800 |
| commit | 22b0489f80dae5242f19c4ce892b50d3685dbf82 (patch) | |
| tree | 9045b869e9ae7c7ecfe8d15a8e5850ee7bc8e8fa /src/libcore/ops | |
| parent | 6f70a11a831992fe86a935a0d649d3aa6b16dc50 (diff) | |
Add the emptiness condition to the docs; add a PartialOrd example with NAN
Diffstat (limited to 'src/libcore/ops')
| -rw-r--r-- | src/libcore/ops/range.rs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs index 4e4d3347523..8a45444f1ab 100644 --- a/src/libcore/ops/range.rs +++ b/src/libcore/ops/range.rs @@ -60,7 +60,7 @@ impl fmt::Debug for RangeFull { /// (`start..end`). /// /// The `Range` `start..end` contains all values with `x >= start` and -/// `x < end`. +/// `x < end`. It is empty unless `start < end`. /// /// # Examples /// @@ -124,6 +124,17 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> { /// assert!( (3..3).is_empty()); /// assert!( (3..2).is_empty()); /// ``` + /// + /// The range is empty if either side is incomparable: + /// + /// ``` + /// #![feature(range_is_empty,inclusive_range_syntax)] + /// + /// use std::f32::NAN; + /// assert!(!(3.0..5.0).is_empty()); + /// assert!( (3.0..NAN).is_empty()); + /// assert!( (NAN..5.0).is_empty()); + /// ``` #[unstable(feature = "range_is_empty", reason = "recently added", issue = "48111")] pub fn is_empty(&self) -> bool { !(self.start < self.end) @@ -260,7 +271,7 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> { /// An range bounded inclusively below and above (`start..=end`). /// /// The `RangeInclusive` `start..=end` contains all values with `x >= start` -/// and `x <= end`. +/// and `x <= end`. It is empty unless `start <= end`. /// /// This iterator is [fused], but the specific values of `start` and `end` after /// iteration has finished are **unspecified** other than that [`.is_empty()`] @@ -337,6 +348,17 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> { /// assert!( (3..=2).is_empty()); /// ``` /// + /// The range is empty if either side is incomparable: + /// + /// ``` + /// #![feature(range_is_empty,inclusive_range_syntax)] + /// + /// use std::f32::NAN; + /// assert!(!(3.0..=5.0).is_empty()); + /// assert!( (3.0..=NAN).is_empty()); + /// assert!( (NAN..=5.0).is_empty()); + /// ``` + /// /// This method returns `true` after iteration has finished: /// /// ``` |
