@@ -1527,142 +1527,26 @@ impl<T: Hash> Hash for Vec<T> {
1527
1527
1528
1528
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1529
1529
#[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1530
- impl < T > Index < usize > for Vec < T > {
1531
- type Output = T ;
1532
-
1533
- #[ inline]
1534
- fn index ( & self , index : usize ) -> & T {
1535
- // NB built-in indexing via `&[T]`
1536
- & ( * * self ) [ index]
1537
- }
1538
- }
1539
-
1540
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1541
- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1542
- impl < T > IndexMut < usize > for Vec < T > {
1543
- #[ inline]
1544
- fn index_mut ( & mut self , index : usize ) -> & mut T {
1545
- // NB built-in indexing via `&mut [T]`
1546
- & mut ( * * self ) [ index]
1547
- }
1548
- }
1549
-
1550
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1551
- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1552
- impl < T > ops:: Index < ops:: Range < usize > > for Vec < T > {
1553
- type Output = [ T ] ;
1554
-
1555
- #[ inline]
1556
- fn index ( & self , index : ops:: Range < usize > ) -> & [ T ] {
1557
- Index :: index ( & * * self , index)
1558
- }
1559
- }
1560
-
1561
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1562
- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1563
- impl < T > ops:: Index < ops:: RangeTo < usize > > for Vec < T > {
1564
- type Output = [ T ] ;
1565
-
1566
- #[ inline]
1567
- fn index ( & self , index : ops:: RangeTo < usize > ) -> & [ T ] {
1568
- Index :: index ( & * * self , index)
1569
- }
1570
- }
1571
-
1572
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1573
- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1574
- impl < T > ops:: Index < ops:: RangeFrom < usize > > for Vec < T > {
1575
- type Output = [ T ] ;
1576
-
1577
- #[ inline]
1578
- fn index ( & self , index : ops:: RangeFrom < usize > ) -> & [ T ] {
1579
- Index :: index ( & * * self , index)
1580
- }
1581
- }
1582
-
1583
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1584
- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1585
- impl < T > ops:: Index < ops:: RangeFull > for Vec < T > {
1586
- type Output = [ T ] ;
1587
-
1588
- #[ inline]
1589
- fn index ( & self , _index : ops:: RangeFull ) -> & [ T ] {
1590
- self
1591
- }
1592
- }
1593
-
1594
- #[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
1595
- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1596
- impl < T > ops:: Index < ops:: RangeInclusive < usize > > for Vec < T > {
1597
- type Output = [ T ] ;
1598
-
1599
- #[ inline]
1600
- fn index ( & self , index : ops:: RangeInclusive < usize > ) -> & [ T ] {
1601
- Index :: index ( & * * self , index)
1602
- }
1603
- }
1604
-
1605
- #[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
1606
- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1607
- impl < T > ops:: Index < ops:: RangeToInclusive < usize > > for Vec < T > {
1608
- type Output = [ T ] ;
1530
+ impl < T , I > Index < I > for Vec < T >
1531
+ where
1532
+ I : :: core:: slice:: SliceIndex < [ T ] > ,
1533
+ {
1534
+ type Output = I :: Output ;
1609
1535
1610
1536
#[ inline]
1611
- fn index ( & self , index : ops :: RangeToInclusive < usize > ) -> & [ T ] {
1537
+ fn index ( & self , index : I ) -> & Self :: Output {
1612
1538
Index :: index ( & * * self , index)
1613
1539
}
1614
1540
}
1615
1541
1616
1542
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1617
1543
#[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1618
- impl < T > ops:: IndexMut < ops:: Range < usize > > for Vec < T > {
1619
- #[ inline]
1620
- fn index_mut ( & mut self , index : ops:: Range < usize > ) -> & mut [ T ] {
1621
- IndexMut :: index_mut ( & mut * * self , index)
1622
- }
1623
- }
1624
-
1625
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1626
- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1627
- impl < T > ops:: IndexMut < ops:: RangeTo < usize > > for Vec < T > {
1628
- #[ inline]
1629
- fn index_mut ( & mut self , index : ops:: RangeTo < usize > ) -> & mut [ T ] {
1630
- IndexMut :: index_mut ( & mut * * self , index)
1631
- }
1632
- }
1633
-
1634
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1635
- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1636
- impl < T > ops:: IndexMut < ops:: RangeFrom < usize > > for Vec < T > {
1637
- #[ inline]
1638
- fn index_mut ( & mut self , index : ops:: RangeFrom < usize > ) -> & mut [ T ] {
1639
- IndexMut :: index_mut ( & mut * * self , index)
1640
- }
1641
- }
1642
-
1643
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1644
- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1645
- impl < T > ops:: IndexMut < ops:: RangeFull > for Vec < T > {
1646
- #[ inline]
1647
- fn index_mut ( & mut self , _index : ops:: RangeFull ) -> & mut [ T ] {
1648
- self
1649
- }
1650
- }
1651
-
1652
- #[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
1653
- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1654
- impl < T > ops:: IndexMut < ops:: RangeInclusive < usize > > for Vec < T > {
1655
- #[ inline]
1656
- fn index_mut ( & mut self , index : ops:: RangeInclusive < usize > ) -> & mut [ T ] {
1657
- IndexMut :: index_mut ( & mut * * self , index)
1658
- }
1659
- }
1660
-
1661
- #[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
1662
- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1663
- impl < T > ops:: IndexMut < ops:: RangeToInclusive < usize > > for Vec < T > {
1544
+ impl < T , I > IndexMut < I > for Vec < T >
1545
+ where
1546
+ I : :: core:: slice:: SliceIndex < [ T ] > ,
1547
+ {
1664
1548
#[ inline]
1665
- fn index_mut ( & mut self , index : ops :: RangeToInclusive < usize > ) -> & mut [ T ] {
1549
+ fn index_mut ( & mut self , index : I ) -> & mut Self :: Output {
1666
1550
IndexMut :: index_mut ( & mut * * self , index)
1667
1551
}
1668
1552
}
0 commit comments