@@ -745,9 +745,7 @@ impl<T> Vec<T> {
745
745
/// ```
746
746
#[ unstable( feature = "collections" ,
747
747
reason = "recently added, matches RFC" ) ]
748
- pub fn drain < R > ( & mut self , range : R ) -> Drain < T > where
749
- R : RangeArgument < usize > ,
750
- {
748
+ pub fn drain < R > ( & mut self , range : R ) -> Drain < T > where R : RangeArgument < usize > {
751
749
// Memory safety
752
750
//
753
751
// When the Drain is first created, it shortens the length of
@@ -1828,8 +1826,7 @@ impl<T> Drop for IntoIter<T> {
1828
1826
1829
1827
/// A draining iterator for `Vec<T>`.
1830
1828
#[ unstable( feature = "collections" , reason = "recently added" ) ]
1831
- pub struct Drain < ' a , T : ' a >
1832
- {
1829
+ pub struct Drain < ' a , T : ' a > {
1833
1830
/// Index of tail to preserve
1834
1831
tail_start : usize ,
1835
1832
/// Length of tail
@@ -1844,52 +1841,39 @@ unsafe impl<'a, T: Sync> Sync for Drain<'a, T> {}
1844
1841
unsafe impl < ' a , T : Send > Send for Drain < ' a , T > { }
1845
1842
1846
1843
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1847
- impl < ' a , T > Iterator for Drain < ' a , T >
1848
- {
1844
+ impl < ' a , T > Iterator for Drain < ' a , T > {
1849
1845
type Item = T ;
1850
1846
1851
1847
#[ inline]
1852
- fn next ( & mut self ) -> Option < T >
1853
- {
1854
- match self . iter . next ( ) {
1855
- None => None ,
1856
- Some ( elt) => {
1857
- unsafe {
1858
- Some ( ptr:: read ( elt as * const _ ) )
1859
- }
1848
+ fn next ( & mut self ) -> Option < T > {
1849
+ self . iter . next ( ) . map ( |elt|
1850
+ unsafe {
1851
+ ptr:: read ( elt as * const _ )
1860
1852
}
1861
- }
1853
+ )
1862
1854
}
1863
1855
1864
- fn size_hint ( & self ) -> ( usize , Option < usize > )
1865
- {
1856
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
1866
1857
self . iter . size_hint ( )
1867
1858
}
1868
1859
}
1869
1860
1870
1861
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1871
- impl < ' a , T > DoubleEndedIterator for Drain < ' a , T >
1872
- {
1862
+ impl < ' a , T > DoubleEndedIterator for Drain < ' a , T > {
1873
1863
#[ inline]
1874
- fn next_back ( & mut self ) -> Option < T >
1875
- {
1876
- match self . iter . next_back ( ) {
1877
- None => None ,
1878
- Some ( elt) => {
1879
- unsafe {
1880
- Some ( ptr:: read ( elt as * const _ ) )
1881
- }
1864
+ fn next_back ( & mut self ) -> Option < T > {
1865
+ self . iter . next_back ( ) . map ( |elt|
1866
+ unsafe {
1867
+ ptr:: read ( elt as * const _ )
1882
1868
}
1883
- }
1869
+ )
1884
1870
}
1885
1871
}
1886
1872
1887
1873
#[ unsafe_destructor]
1888
1874
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1889
- impl < ' a , T > Drop for Drain < ' a , T >
1890
- {
1891
- fn drop ( & mut self )
1892
- {
1875
+ impl < ' a , T > Drop for Drain < ' a , T > {
1876
+ fn drop ( & mut self ) {
1893
1877
// exhaust self first
1894
1878
while let Some ( _) = self . next ( ) { }
1895
1879
0 commit comments