68
68
//! ```
69
69
//!
70
70
//! See the documentation for each trait for an example implementation.
71
+ //!
72
+ //! This example shows the behavior of the various `Range*` structs.
73
+ //!
74
+ //! ```rust
75
+ //! #![feature(inclusive_range_syntax)]
76
+ //!
77
+ //! let arr = [0, 1, 2, 3, 4];
78
+ //!
79
+ //! assert_eq!(arr[ .. ], [0,1,2,3,4]); // RangeFull
80
+ //! assert_eq!(arr[ ..3], [0,1,2 ]); // RangeTo
81
+ //! assert_eq!(arr[1.. ], [ 1,2,3,4]); // RangeFrom
82
+ //! assert_eq!(arr[1..3], [ 1,2 ]); // Range
83
+ //!
84
+ //! assert_eq!(arr[ ...3], [0,1,2,3 ]); // RangeToIncusive
85
+ //! assert_eq!(arr[1...3], [ 1,2,3 ]); // RangeInclusive
86
+ //! ```
71
87
72
88
#![ stable( feature = "rust1" , since = "1.0.0" ) ]
73
89
@@ -1594,11 +1610,12 @@ pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
1594
1610
///
1595
1611
/// ```
1596
1612
/// let arr = [0, 1, 2, 3];
1597
- /// assert_eq!(arr[ .. ], [0,1,2,3]); // RangeFull
1598
- /// assert_eq!(arr[ ..3], [0,1,2 ]);
1599
- /// assert_eq!(arr[1.. ], [ 1,2,3]);
1600
- /// assert_eq!(arr[1..3], [ 1,2 ]);
1613
+ /// assert_eq!(arr[ .. ], [0, 1, 2, 3]);
1601
1614
/// ```
1615
+ ///
1616
+ /// See the [module examples] for the behavior of other range structs.
1617
+ ///
1618
+ /// [module examples]: ../#Examples
1602
1619
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
1603
1620
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1604
1621
pub struct RangeFull ;
@@ -1623,12 +1640,13 @@ impl fmt::Debug for RangeFull {
1623
1640
/// assert_eq!(3+4+5, (3..6).sum());
1624
1641
///
1625
1642
/// let arr = [0, 1, 2, 3];
1626
- /// assert_eq!(arr[ .. ], [0,1,2,3]);
1627
- /// assert_eq!(arr[ ..3], [0,1,2 ]);
1628
- /// assert_eq!(arr[1.. ], [ 1,2,3]);
1629
- /// assert_eq!(arr[1..3], [ 1,2 ]); // Range
1643
+ /// assert_eq!(arr[1..3], [1, 2]);
1630
1644
/// }
1631
1645
/// ```
1646
+ ///
1647
+ /// See the [module examples] for the behavior of other range structs.
1648
+ ///
1649
+ /// [module examples]: ../#Examples
1632
1650
#[ derive( Clone , PartialEq , Eq , Hash ) ] // not Copy -- see #27186
1633
1651
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1634
1652
pub struct Range < Idx > {
@@ -1686,12 +1704,13 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
1686
1704
/// assert_eq!(2+3+4, (2..).take(3).sum());
1687
1705
///
1688
1706
/// let arr = [0, 1, 2, 3];
1689
- /// assert_eq!(arr[ .. ], [0,1,2,3]);
1690
- /// assert_eq!(arr[ ..3], [0,1,2 ]);
1691
- /// assert_eq!(arr[1.. ], [ 1,2,3]); // RangeFrom
1692
- /// assert_eq!(arr[1..3], [ 1,2 ]);
1707
+ /// assert_eq!(arr[1.. ], [1, 2, 3]);
1693
1708
/// }
1694
1709
/// ```
1710
+ ///
1711
+ /// See the [module examples] for the behavior of other range structs.
1712
+ ///
1713
+ /// [module examples]: ../#Examples
1695
1714
#[ derive( Clone , PartialEq , Eq , Hash ) ] // not Copy -- see #27186
1696
1715
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1697
1716
pub struct RangeFrom < Idx > {
@@ -1736,12 +1755,13 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
1736
1755
/// assert_eq!((..5), std::ops::RangeTo{ end: 5 });
1737
1756
///
1738
1757
/// let arr = [0, 1, 2, 3];
1739
- /// assert_eq!(arr[ .. ], [0,1,2,3]);
1740
- /// assert_eq!(arr[ ..3], [0,1,2 ]); // RangeTo
1741
- /// assert_eq!(arr[1.. ], [ 1,2,3]);
1742
- /// assert_eq!(arr[1..3], [ 1,2 ]);
1758
+ /// assert_eq!(arr[ ..3], [0, 1, 2]);
1743
1759
/// }
1744
1760
/// ```
1761
+ ///
1762
+ /// See the [module examples] for the behavior of other range structs.
1763
+ ///
1764
+ /// [module examples]: ../#Examples
1745
1765
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
1746
1766
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1747
1767
pub struct RangeTo < Idx > {
@@ -1788,10 +1808,13 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
1788
1808
/// assert_eq!(3+4+5, (3...5).sum());
1789
1809
///
1790
1810
/// let arr = [0, 1, 2, 3];
1791
- /// assert_eq!(arr[ ...2], [0,1,2 ]);
1792
- /// assert_eq!(arr[1...2], [ 1,2 ]); // RangeInclusive
1811
+ /// assert_eq!(arr[1...2], [1, 2]);
1793
1812
/// }
1794
1813
/// ```
1814
+ ///
1815
+ /// See the [module examples] for the behavior of other range structs.
1816
+ ///
1817
+ /// [module examples]: ../#Examples
1795
1818
#[ derive( Clone , PartialEq , Eq , Hash ) ] // not Copy -- see #27186
1796
1819
#[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
1797
1820
pub enum RangeInclusive < Idx > {
@@ -1875,10 +1898,13 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
1875
1898
/// assert_eq!((...5), std::ops::RangeToInclusive{ end: 5 });
1876
1899
///
1877
1900
/// let arr = [0, 1, 2, 3];
1878
- /// assert_eq!(arr[ ...2], [0,1,2 ]); // RangeToInclusive
1879
- /// assert_eq!(arr[1...2], [ 1,2 ]);
1901
+ /// assert_eq!(arr[ ...2], [0, 1, 2]);
1880
1902
/// }
1881
1903
/// ```
1904
+ ///
1905
+ /// See the [module examples] for the behavior of other range structs.
1906
+ ///
1907
+ /// [module examples]: ../#Examples
1882
1908
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
1883
1909
#[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
1884
1910
pub struct RangeToInclusive < Idx > {
0 commit comments