@@ -1610,17 +1610,33 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
1610
1610
///
1611
1611
/// It cannot serve as an iterator because it doesn't have a starting point.
1612
1612
///
1613
+ /// # Examples
1614
+ ///
1615
+ /// The `..{integer}` syntax is a `RangeTo`:
1616
+ ///
1617
+ /// ```
1618
+ /// assert_eq!((..5), std::ops::RangeTo{ end: 5 });
1613
1619
/// ```
1614
- /// fn main() {
1615
- /// assert_eq!((..5), std::ops::RangeTo{ end: 5 });
1616
1620
///
1617
- /// let arr = [0, 1, 2, 3];
1618
- /// assert_eq!(arr[ .. ], [0,1,2,3]);
1619
- /// assert_eq!(arr[ ..3], [0,1,2 ]); // RangeTo
1620
- /// assert_eq!(arr[1.. ], [ 1,2,3]);
1621
- /// assert_eq!(arr[1..3], [ 1,2 ]);
1621
+ /// It does not have an `IntoIterator` implementation, so you can't use it in a
1622
+ /// `for` loop directly. This won't compile:
1623
+ ///
1624
+ /// ```ignore
1625
+ /// for i in ..5 {
1626
+ /// // ...
1622
1627
/// }
1623
1628
/// ```
1629
+ ///
1630
+ /// When used as a slicing index, `RangeTo` produces a slice of all array
1631
+ /// elements before the index indicated by `end`.
1632
+ ///
1633
+ /// ```
1634
+ /// let arr = [0, 1, 2, 3];
1635
+ /// assert_eq!(arr[ .. ], [0,1,2,3]);
1636
+ /// assert_eq!(arr[ ..3], [0,1,2 ]); // RangeTo
1637
+ /// assert_eq!(arr[1.. ], [ 1,2,3]);
1638
+ /// assert_eq!(arr[1..3], [ 1,2 ]);
1639
+ /// ```
1624
1640
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
1625
1641
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1626
1642
pub struct RangeTo < Idx > {
@@ -1748,16 +1764,31 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
1748
1764
///
1749
1765
/// # Examples
1750
1766
///
1767
+ /// The `...{integer}` syntax is a `RangeToInclusive`:
1768
+ ///
1751
1769
/// ```
1752
1770
/// #![feature(inclusive_range,inclusive_range_syntax)]
1753
- /// fn main() {
1754
- /// assert_eq!((...5), std::ops::RangeToInclusive{ end: 5 });
1771
+ /// assert_eq!((...5), std::ops::RangeToInclusive{ end: 5 });
1772
+ /// ```
1755
1773
///
1756
- /// let arr = [0, 1, 2, 3];
1757
- /// assert_eq!(arr[ ...2], [0,1,2 ]); // RangeToInclusive
1758
- /// assert_eq!(arr[1...2], [ 1,2 ]);
1774
+ /// It does not have an `IntoIterator` implementation, so you can't use it in a
1775
+ /// `for` loop directly. This won't compile:
1776
+ ///
1777
+ /// ```ignore
1778
+ /// for i in ...5 {
1779
+ /// // ...
1759
1780
/// }
1760
1781
/// ```
1782
+ ///
1783
+ /// When used as a slicing index, `RangeToInclusive` produces a slice of all
1784
+ /// array elements up to and including the index indicated by `end`.
1785
+ ///
1786
+ /// ```
1787
+ /// #![feature(inclusive_range_syntax)]
1788
+ /// let arr = [0, 1, 2, 3];
1789
+ /// assert_eq!(arr[ ...2], [0,1,2 ]); // RangeToInclusive
1790
+ /// assert_eq!(arr[1...2], [ 1,2 ]);
1791
+ /// ```
1761
1792
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
1762
1793
#[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
1763
1794
pub struct RangeToInclusive < Idx > {
0 commit comments