Skip to content

Commit bd5d6ca

Browse files
author
Ulrik Sverdrup
committed
collections: Use Option::map
1 parent 6dc48c8 commit bd5d6ca

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/libcollections/vec.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,14 +1848,11 @@ impl<'a, T> Iterator for Drain<'a, T>
18481848
#[inline]
18491849
fn next(&mut self) -> Option<T>
18501850
{
1851-
match self.iter.next() {
1852-
None => None,
1853-
Some(elt) => {
1854-
unsafe {
1855-
Some(ptr::read(elt as *const _))
1856-
}
1851+
self.iter.next().map(|elt|
1852+
unsafe {
1853+
ptr::read(elt as *const _)
18571854
}
1858-
}
1855+
)
18591856
}
18601857

18611858
fn size_hint(&self) -> (usize, Option<usize>)
@@ -1870,14 +1867,11 @@ impl<'a, T> DoubleEndedIterator for Drain<'a, T>
18701867
#[inline]
18711868
fn next_back(&mut self) -> Option<T>
18721869
{
1873-
match self.iter.next_back() {
1874-
None => None,
1875-
Some(elt) => {
1876-
unsafe {
1877-
Some(ptr::read(elt as *const _))
1878-
}
1870+
self.iter.next_back().map(|elt|
1871+
unsafe {
1872+
ptr::read(elt as *const _)
18791873
}
1880-
}
1874+
)
18811875
}
18821876
}
18831877

0 commit comments

Comments
 (0)