140
140
//!
141
141
//! // `consume_and_return_x` can no longer be invoked at this point
142
142
//! ```
143
+ //!
144
+ //! This example shows the behavior of the various `Range*` structs.
145
+ //!
146
+ //! ```rust
147
+ //! #![feature(inclusive_range_syntax)]
148
+ //!
149
+ //! let arr = [0, 1, 2, 3, 4];
150
+ //!
151
+ //! assert_eq!(arr[ .. ], [0,1,2,3,4]); // RangeFull
152
+ //! assert_eq!(arr[ ..3], [0,1,2 ]); // RangeTo
153
+ //! assert_eq!(arr[1.. ], [ 1,2,3,4]); // RangeFrom
154
+ //! assert_eq!(arr[1..3], [ 1,2 ]); // Range
155
+ //!
156
+ //! assert_eq!(arr[ ...3], [0,1,2,3 ]); // RangeToIncusive
157
+ //! assert_eq!(arr[1...3], [ 1,2,3 ]); // RangeInclusive
158
+ //! ```
143
159
144
160
#![ stable( feature = "rust1" , since = "1.0.0" ) ]
145
161
@@ -1881,11 +1897,12 @@ pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
1881
1897
///
1882
1898
/// ```
1883
1899
/// let arr = [0, 1, 2, 3];
1884
- /// assert_eq!(arr[ .. ], [0,1,2,3]); // RangeFull
1885
- /// assert_eq!(arr[ ..3], [0,1,2 ]);
1886
- /// assert_eq!(arr[1.. ], [ 1,2,3]);
1887
- /// assert_eq!(arr[1..3], [ 1,2 ]);
1900
+ /// assert_eq!(arr[ .. ], [0, 1, 2, 3]);
1888
1901
/// ```
1902
+ ///
1903
+ /// See the [module examples] for the behavior of other range structs.
1904
+ ///
1905
+ /// [module examples]: ../#Examples
1889
1906
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
1890
1907
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1891
1908
pub struct RangeFull ;
@@ -1910,12 +1927,13 @@ impl fmt::Debug for RangeFull {
1910
1927
/// assert_eq!(3+4+5, (3..6).sum());
1911
1928
///
1912
1929
/// let arr = [0, 1, 2, 3];
1913
- /// assert_eq!(arr[ .. ], [0,1,2,3]);
1914
- /// assert_eq!(arr[ ..3], [0,1,2 ]);
1915
- /// assert_eq!(arr[1.. ], [ 1,2,3]);
1916
- /// assert_eq!(arr[1..3], [ 1,2 ]); // Range
1930
+ /// assert_eq!(arr[1..3], [1, 2]);
1917
1931
/// }
1918
1932
/// ```
1933
+ ///
1934
+ /// See the [module examples] for the behavior of other range structs.
1935
+ ///
1936
+ /// [module examples]: ../#Examples
1919
1937
#[ derive( Clone , PartialEq , Eq , Hash ) ] // not Copy -- see #27186
1920
1938
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1921
1939
pub struct Range < Idx > {
@@ -1973,12 +1991,13 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
1973
1991
/// assert_eq!(2+3+4, (2..).take(3).sum());
1974
1992
///
1975
1993
/// let arr = [0, 1, 2, 3];
1976
- /// assert_eq!(arr[ .. ], [0,1,2,3]);
1977
- /// assert_eq!(arr[ ..3], [0,1,2 ]);
1978
- /// assert_eq!(arr[1.. ], [ 1,2,3]); // RangeFrom
1979
- /// assert_eq!(arr[1..3], [ 1,2 ]);
1994
+ /// assert_eq!(arr[1.. ], [1, 2, 3]);
1980
1995
/// }
1981
1996
/// ```
1997
+ ///
1998
+ /// See the [module examples] for the behavior of other range structs.
1999
+ ///
2000
+ /// [module examples]: ../#Examples
1982
2001
#[ derive( Clone , PartialEq , Eq , Hash ) ] // not Copy -- see #27186
1983
2002
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1984
2003
pub struct RangeFrom < Idx > {
@@ -2040,11 +2059,12 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
2040
2059
///
2041
2060
/// ```
2042
2061
/// let arr = [0, 1, 2, 3];
2043
- /// assert_eq!(arr[ .. ], [0,1,2,3]);
2044
- /// assert_eq!(arr[ ..3], [0,1,2 ]); // RangeTo
2045
- /// assert_eq!(arr[1.. ], [ 1,2,3]);
2046
- /// assert_eq!(arr[1..3], [ 1,2 ]);
2062
+ /// assert_eq!(arr[ ..3], [0, 1, 2]);
2047
2063
/// ```
2064
+ ///
2065
+ /// See the [module examples] for the behavior of other range structs.
2066
+ ///
2067
+ /// [module examples]: ../#Examples
2048
2068
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
2049
2069
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2050
2070
pub struct RangeTo < Idx > {
@@ -2091,10 +2111,13 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
2091
2111
/// assert_eq!(3+4+5, (3...5).sum());
2092
2112
///
2093
2113
/// let arr = [0, 1, 2, 3];
2094
- /// assert_eq!(arr[ ...2], [0,1,2 ]);
2095
- /// assert_eq!(arr[1...2], [ 1,2 ]); // RangeInclusive
2114
+ /// assert_eq!(arr[1...2], [1, 2]);
2096
2115
/// }
2097
2116
/// ```
2117
+ ///
2118
+ /// See the [module examples] for the behavior of other range structs.
2119
+ ///
2120
+ /// [module examples]: ../#Examples
2098
2121
#[ derive( Clone , PartialEq , Eq , Hash ) ] // not Copy -- see #27186
2099
2122
#[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
2100
2123
pub enum RangeInclusive < Idx > {
@@ -2192,11 +2215,13 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
2192
2215
/// array elements up to and including the index indicated by `end`.
2193
2216
///
2194
2217
/// ```
2195
- /// #![feature(inclusive_range_syntax)]
2196
2218
/// let arr = [0, 1, 2, 3];
2197
- /// assert_eq!(arr[ ...2], [0,1,2 ]); // RangeToInclusive
2198
- /// assert_eq!(arr[1...2], [ 1,2 ]);
2219
+ /// assert_eq!(arr[ ...2], [0, 1, 2]);
2199
2220
/// ```
2221
+ ///
2222
+ /// See the [module examples] for the behavior of other range structs.
2223
+ ///
2224
+ /// [module examples]: ../#Examples
2200
2225
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
2201
2226
#[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
2202
2227
pub struct RangeToInclusive < Idx > {
0 commit comments