@@ -1616,16 +1616,20 @@ pub trait Iterator {
1616
1616
/// Returns the maximum element of an iterator.
1617
1617
///
1618
1618
/// If several elements are equally maximum, the last element is
1619
- /// returned.
1619
+ /// returned. If the iterator is empty, [`None`] is returned.
1620
+ ///
1621
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
1620
1622
///
1621
1623
/// # Examples
1622
1624
///
1623
1625
/// Basic usage:
1624
1626
///
1625
1627
/// ```
1626
1628
/// let a = [1, 2, 3];
1629
+ /// let b: Vec<u32> = Vec::new();
1627
1630
///
1628
1631
/// assert_eq!(a.iter().max(), Some(&3));
1632
+ /// assert_eq!(b.iter().max(), None);
1629
1633
/// ```
1630
1634
#[ inline]
1631
1635
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1642,16 +1646,20 @@ pub trait Iterator {
1642
1646
/// Returns the minimum element of an iterator.
1643
1647
///
1644
1648
/// If several elements are equally minimum, the first element is
1645
- /// returned.
1649
+ /// returned. If the iterator is empty, [`None`] is returned.
1650
+ ///
1651
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
1646
1652
///
1647
1653
/// # Examples
1648
1654
///
1649
1655
/// Basic usage:
1650
1656
///
1651
1657
/// ```
1652
1658
/// let a = [1, 2, 3];
1659
+ /// let b: Vec<u32> = Vec::new();
1653
1660
///
1654
1661
/// assert_eq!(a.iter().min(), Some(&1));
1662
+ /// assert_eq!(b.iter().min(), None);
1655
1663
/// ```
1656
1664
#[ inline]
1657
1665
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1669,7 +1677,9 @@ pub trait Iterator {
1669
1677
/// specified function.
1670
1678
///
1671
1679
/// If several elements are equally maximum, the last element is
1672
- /// returned.
1680
+ /// returned. If the iterator is empty, [`None`] is returned.
1681
+ ///
1682
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
1673
1683
///
1674
1684
/// # Examples
1675
1685
///
@@ -1694,7 +1704,9 @@ pub trait Iterator {
1694
1704
/// specified comparison function.
1695
1705
///
1696
1706
/// If several elements are equally maximum, the last element is
1697
- /// returned.
1707
+ /// returned. If the iterator is empty, [`None`] is returned.
1708
+ ///
1709
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
1698
1710
///
1699
1711
/// # Examples
1700
1712
///
@@ -1719,7 +1731,9 @@ pub trait Iterator {
1719
1731
/// specified function.
1720
1732
///
1721
1733
/// If several elements are equally minimum, the first element is
1722
- /// returned.
1734
+ /// returned. If the iterator is empty, [`None`] is returned.
1735
+ ///
1736
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
1723
1737
///
1724
1738
/// # Examples
1725
1739
///
@@ -1743,7 +1757,9 @@ pub trait Iterator {
1743
1757
/// specified comparison function.
1744
1758
///
1745
1759
/// If several elements are equally minimum, the first element is
1746
- /// returned.
1760
+ /// returned. If the iterator is empty, [`None`] is returned.
1761
+ ///
1762
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
1747
1763
///
1748
1764
/// # Examples
1749
1765
///
0 commit comments