@@ -81,6 +81,10 @@ pub trait SliceExt {
81
81
fn split < P > ( & self , pred : P ) -> Split < Self :: Item , P >
82
82
where P : FnMut ( & Self :: Item ) -> bool ;
83
83
84
+ #[ unstable( feature = "slice_rsplit" , issue = "41020" ) ]
85
+ fn rsplit < P > ( & self , pred : P ) -> RSplit < Self :: Item , P >
86
+ where P : FnMut ( & Self :: Item ) -> bool ;
87
+
84
88
#[ stable( feature = "core" , since = "1.6.0" ) ]
85
89
fn splitn < P > ( & self , n : usize , pred : P ) -> SplitN < Self :: Item , P >
86
90
where P : FnMut ( & Self :: Item ) -> bool ;
@@ -159,6 +163,10 @@ pub trait SliceExt {
159
163
fn split_mut < P > ( & mut self , pred : P ) -> SplitMut < Self :: Item , P >
160
164
where P : FnMut ( & Self :: Item ) -> bool ;
161
165
166
+ #[ unstable( feature = "slice_rsplit" , issue = "41020" ) ]
167
+ fn rsplit_mut < P > ( & mut self , pred : P ) -> RSplitMut < Self :: Item , P >
168
+ where P : FnMut ( & Self :: Item ) -> bool ;
169
+
162
170
#[ stable( feature = "core" , since = "1.6.0" ) ]
163
171
fn splitn_mut < P > ( & mut self , n : usize , pred : P ) -> SplitNMut < Self :: Item , P >
164
172
where P : FnMut ( & Self :: Item ) -> bool ;
@@ -293,6 +301,13 @@ impl<T> SliceExt for [T] {
293
301
}
294
302
}
295
303
304
+ #[ inline]
305
+ fn rsplit < P > ( & self , pred : P ) -> RSplit < T , P >
306
+ where P : FnMut ( & T ) -> bool
307
+ {
308
+ RSplit { inner : self . split ( pred) }
309
+ }
310
+
296
311
#[ inline]
297
312
fn splitn < P > ( & self , n : usize , pred : P ) -> SplitN < T , P >
298
313
where P : FnMut ( & T ) -> bool
@@ -475,6 +490,13 @@ impl<T> SliceExt for [T] {
475
490
SplitMut { v : self , pred : pred, finished : false }
476
491
}
477
492
493
+ #[ inline]
494
+ fn rsplit_mut < P > ( & mut self , pred : P ) -> RSplitMut < T , P >
495
+ where P : FnMut ( & T ) -> bool
496
+ {
497
+ RSplitMut { inner : self . split_mut ( pred) }
498
+ }
499
+
478
500
#[ inline]
479
501
fn splitn_mut < P > ( & mut self , n : usize , pred : P ) -> SplitNMut < T , P >
480
502
where P : FnMut ( & T ) -> bool
@@ -1735,6 +1757,123 @@ impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where
1735
1757
#[ unstable( feature = "fused" , issue = "35602" ) ]
1736
1758
impl < ' a , T , P > FusedIterator for SplitMut < ' a , T , P > where P : FnMut ( & T ) -> bool { }
1737
1759
1760
+ /// An iterator over subslices separated by elements that match a predicate
1761
+ /// function, starting from the end of the slice.
1762
+ ///
1763
+ /// This struct is created by the [`rsplit`] method on [slices].
1764
+ ///
1765
+ /// [`rsplit`]: ../../std/primitive.slice.html#method.rsplit
1766
+ /// [slices]: ../../std/primitive.slice.html
1767
+ #[ unstable( feature = "slice_rsplit" , issue = "41020" ) ]
1768
+ #[ derive( Clone ) ] // Is this correct, or does it incorrectly require `T: Clone`?
1769
+ pub struct RSplit < ' a , T : ' a , P > where P : FnMut ( & T ) -> bool {
1770
+ inner : Split < ' a , T , P >
1771
+ }
1772
+
1773
+ #[ unstable( feature = "slice_rsplit" , issue = "41020" ) ]
1774
+ impl < ' a , T : ' a + fmt:: Debug , P > fmt:: Debug for RSplit < ' a , T , P > where P : FnMut ( & T ) -> bool {
1775
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1776
+ f. debug_struct ( "RSplit" )
1777
+ . field ( "v" , & self . inner . v )
1778
+ . field ( "finished" , & self . inner . finished )
1779
+ . finish ( )
1780
+ }
1781
+ }
1782
+
1783
+ #[ unstable( feature = "slice_rsplit" , issue = "41020" ) ]
1784
+ impl < ' a , T , P > Iterator for RSplit < ' a , T , P > where P : FnMut ( & T ) -> bool {
1785
+ type Item = & ' a [ T ] ;
1786
+
1787
+ #[ inline]
1788
+ fn next ( & mut self ) -> Option < & ' a [ T ] > {
1789
+ self . inner . next_back ( )
1790
+ }
1791
+
1792
+ #[ inline]
1793
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
1794
+ self . inner . size_hint ( )
1795
+ }
1796
+ }
1797
+
1798
+ #[ unstable( feature = "slice_rsplit" , issue = "41020" ) ]
1799
+ impl < ' a , T , P > DoubleEndedIterator for RSplit < ' a , T , P > where P : FnMut ( & T ) -> bool {
1800
+ #[ inline]
1801
+ fn next_back ( & mut self ) -> Option < & ' a [ T ] > {
1802
+ self . inner . next ( )
1803
+ }
1804
+ }
1805
+
1806
+ #[ unstable( feature = "slice_rsplit" , issue = "41020" ) ]
1807
+ impl < ' a , T , P > SplitIter for RSplit < ' a , T , P > where P : FnMut ( & T ) -> bool {
1808
+ #[ inline]
1809
+ fn finish ( & mut self ) -> Option < & ' a [ T ] > {
1810
+ self . inner . finish ( )
1811
+ }
1812
+ }
1813
+
1814
+ //#[unstable(feature = "fused", issue = "35602")]
1815
+ #[ unstable( feature = "slice_rsplit" , issue = "41020" ) ]
1816
+ impl < ' a , T , P > FusedIterator for RSplit < ' a , T , P > where P : FnMut ( & T ) -> bool { }
1817
+
1818
+ /// An iterator over the subslices of the vector which are separated
1819
+ /// by elements that match `pred`, starting from the end of the slice.
1820
+ ///
1821
+ /// This struct is created by the [`rsplit_mut`] method on [slices].
1822
+ ///
1823
+ /// [`rsplit_mut`]: ../../std/primitive.slice.html#method.rsplit_mut
1824
+ /// [slices]: ../../std/primitive.slice.html
1825
+ #[ unstable( feature = "slice_rsplit" , issue = "41020" ) ]
1826
+ pub struct RSplitMut < ' a , T : ' a , P > where P : FnMut ( & T ) -> bool {
1827
+ inner : SplitMut < ' a , T , P >
1828
+ }
1829
+
1830
+ #[ unstable( feature = "slice_rsplit" , issue = "41020" ) ]
1831
+ impl < ' a , T : ' a + fmt:: Debug , P > fmt:: Debug for RSplitMut < ' a , T , P > where P : FnMut ( & T ) -> bool {
1832
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1833
+ f. debug_struct ( "RSplitMut" )
1834
+ . field ( "v" , & self . inner . v )
1835
+ . field ( "finished" , & self . inner . finished )
1836
+ . finish ( )
1837
+ }
1838
+ }
1839
+
1840
+ #[ unstable( feature = "slice_rsplit" , issue = "41020" ) ]
1841
+ impl < ' a , T , P > SplitIter for RSplitMut < ' a , T , P > where P : FnMut ( & T ) -> bool {
1842
+ #[ inline]
1843
+ fn finish ( & mut self ) -> Option < & ' a mut [ T ] > {
1844
+ self . inner . finish ( )
1845
+ }
1846
+ }
1847
+
1848
+ #[ unstable( feature = "slice_rsplit" , issue = "41020" ) ]
1849
+ impl < ' a , T , P > Iterator for RSplitMut < ' a , T , P > where P : FnMut ( & T ) -> bool {
1850
+ type Item = & ' a mut [ T ] ;
1851
+
1852
+ #[ inline]
1853
+ fn next ( & mut self ) -> Option < & ' a mut [ T ] > {
1854
+ self . inner . next_back ( )
1855
+ }
1856
+
1857
+ #[ inline]
1858
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
1859
+ self . inner . size_hint ( )
1860
+ }
1861
+ }
1862
+
1863
+ #[ unstable( feature = "slice_rsplit" , issue = "41020" ) ]
1864
+ impl < ' a , T , P > DoubleEndedIterator for RSplitMut < ' a , T , P > where
1865
+ P : FnMut ( & T ) -> bool ,
1866
+ {
1867
+ #[ inline]
1868
+ fn next_back ( & mut self ) -> Option < & ' a mut [ T ] > {
1869
+ self . inner . next ( )
1870
+ }
1871
+ }
1872
+
1873
+ //#[unstable(feature = "fused", issue = "35602")]
1874
+ #[ unstable( feature = "slice_rsplit" , issue = "41020" ) ]
1875
+ impl < ' a , T , P > FusedIterator for RSplitMut < ' a , T , P > where P : FnMut ( & T ) -> bool { }
1876
+
1738
1877
/// An private iterator over subslices separated by elements that
1739
1878
/// match a predicate function, splitting at most a fixed number of
1740
1879
/// times.
0 commit comments