@@ -1873,17 +1873,33 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
1873
1873
///
1874
1874
/// It cannot serve as an iterator because it doesn't have a starting point.
1875
1875
///
1876
+ /// # Examples
1877
+ ///
1878
+ /// The `..{integer}` syntax is a `RangeTo`:
1879
+ ///
1880
+ /// ```
1881
+ /// assert_eq!((..5), std::ops::RangeTo{ end: 5 });
1876
1882
/// ```
1877
- /// fn main() {
1878
- /// assert_eq!((..5), std::ops::RangeTo{ end: 5 });
1879
1883
///
1880
- /// let arr = [0, 1, 2, 3];
1881
- /// assert_eq!(arr[ .. ], [0,1,2,3]);
1882
- /// assert_eq!(arr[ ..3], [0,1,2 ]); // RangeTo
1883
- /// assert_eq!(arr[1.. ], [ 1,2,3]);
1884
- /// assert_eq!(arr[1..3], [ 1,2 ]);
1884
+ /// It does not have an `IntoIterator` implementation, so you can't use it in a
1885
+ /// `for` loop directly. This won't compile:
1886
+ ///
1887
+ /// ```ignore
1888
+ /// for i in ..5 {
1889
+ /// // ...
1885
1890
/// }
1886
1891
/// ```
1892
+ ///
1893
+ /// When used as a slicing index, `RangeTo` produces a slice of all array
1894
+ /// elements before the index indicated by `end`.
1895
+ ///
1896
+ /// ```
1897
+ /// let arr = [0, 1, 2, 3];
1898
+ /// assert_eq!(arr[ .. ], [0,1,2,3]);
1899
+ /// assert_eq!(arr[ ..3], [0,1,2 ]); // RangeTo
1900
+ /// assert_eq!(arr[1.. ], [ 1,2,3]);
1901
+ /// assert_eq!(arr[1..3], [ 1,2 ]);
1902
+ /// ```
1887
1903
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
1888
1904
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1889
1905
pub struct RangeTo < Idx > {
@@ -2011,16 +2027,31 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
2011
2027
///
2012
2028
/// # Examples
2013
2029
///
2030
+ /// The `...{integer}` syntax is a `RangeToInclusive`:
2031
+ ///
2014
2032
/// ```
2015
2033
/// #![feature(inclusive_range,inclusive_range_syntax)]
2016
- /// fn main() {
2017
- /// assert_eq!((...5), std::ops::RangeToInclusive{ end: 5 });
2034
+ /// assert_eq!((...5), std::ops::RangeToInclusive{ end: 5 });
2035
+ /// ```
2018
2036
///
2019
- /// let arr = [0, 1, 2, 3];
2020
- /// assert_eq!(arr[ ...2], [0,1,2 ]); // RangeToInclusive
2021
- /// assert_eq!(arr[1...2], [ 1,2 ]);
2037
+ /// It does not have an `IntoIterator` implementation, so you can't use it in a
2038
+ /// `for` loop directly. This won't compile:
2039
+ ///
2040
+ /// ```ignore
2041
+ /// for i in ...5 {
2042
+ /// // ...
2022
2043
/// }
2023
2044
/// ```
2045
+ ///
2046
+ /// When used as a slicing index, `RangeToInclusive` produces a slice of all
2047
+ /// array elements up to and including the index indicated by `end`.
2048
+ ///
2049
+ /// ```
2050
+ /// #![feature(inclusive_range_syntax)]
2051
+ /// let arr = [0, 1, 2, 3];
2052
+ /// assert_eq!(arr[ ...2], [0,1,2 ]); // RangeToInclusive
2053
+ /// assert_eq!(arr[1...2], [ 1,2 ]);
2054
+ /// ```
2024
2055
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
2025
2056
#[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
2026
2057
pub struct RangeToInclusive < Idx > {
0 commit comments