diff --git a/src/libcore/iter/range.rs b/src/libcore/iter/range.rs index d6c1420a03c29..66a76a24df45a 100644 --- a/src/libcore/iter/range.rs +++ b/src/libcore/iter/range.rs @@ -252,6 +252,16 @@ impl Iterator for ops::Range { None } + #[inline] + fn last(mut self) -> Option { + self.next_back() + } + + #[inline] + fn min(mut self) -> Option { + self.next() + } + #[inline] fn max(mut self) -> Option { self.next_back() diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index 9cbec8f9e6e88..8997cf9c6bff9 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -1353,10 +1353,14 @@ fn test_range_step() { } #[test] -fn test_range_max() { - assert_eq!((0..100).max(), Some(99)); - assert_eq!((-20..-10).max(), Some(-11)); - assert_eq!((1..1).max(), None); +fn test_range_last_max() { + assert_eq!((0..20).last(), Some(19)); + assert_eq!((-20..0).last(), Some(-1)); + assert_eq!((5..5).last(), None); + + assert_eq!((0..20).max(), Some(19)); + assert_eq!((-20..0).max(), Some(-1)); + assert_eq!((5..5).max(), None); } #[test] @@ -1376,6 +1380,13 @@ fn test_range_inclusive_last_max() { assert_eq!(r.max(), None); } +#[test] +fn test_range_min() { + assert_eq!((0..20).min(), Some(0)); + assert_eq!((-20..0).min(), Some(-20)); + assert_eq!((5..5).min(), None); +} + #[test] fn test_range_inclusive_min() { assert_eq!((0..=20).min(), Some(0));