Skip to content

Commit 0a2a809

Browse files
author
Ulrik Sverdrup
committed
collections: Fix coding style and other review comments for Drain
1 parent 4223a23 commit 0a2a809

File tree

2 files changed

+18
-39
lines changed

2 files changed

+18
-39
lines changed

src/libcollections/range.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@
1111
//! Range syntax.
1212
1313
use core::option::Option::{self, None, Some};
14-
use core::ops::{
15-
RangeFull,
16-
Range,
17-
RangeTo,
18-
RangeFrom
19-
};
14+
use core::ops::{RangeFull, Range, RangeTo, RangeFrom};
2015

2116
#[unstable(feature = "collections", reason = "was just added")]
2217
/// **RangeArgument** is implemented by Rust's built-in range types, produced

src/libcollections/vec.rs

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -745,9 +745,7 @@ impl<T> Vec<T> {
745745
/// ```
746746
#[unstable(feature = "collections",
747747
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> {
751749
// Memory safety
752750
//
753751
// When the Drain is first created, it shortens the length of
@@ -1828,8 +1826,7 @@ impl<T> Drop for IntoIter<T> {
18281826

18291827
/// A draining iterator for `Vec<T>`.
18301828
#[unstable(feature = "collections", reason = "recently added")]
1831-
pub struct Drain<'a, T: 'a>
1832-
{
1829+
pub struct Drain<'a, T: 'a> {
18331830
/// Index of tail to preserve
18341831
tail_start: usize,
18351832
/// Length of tail
@@ -1844,52 +1841,39 @@ unsafe impl<'a, T: Sync> Sync for Drain<'a, T> {}
18441841
unsafe impl<'a, T: Send> Send for Drain<'a, T> {}
18451842

18461843
#[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> {
18491845
type Item = T;
18501846

18511847
#[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 _)
18601852
}
1861-
}
1853+
)
18621854
}
18631855

1864-
fn size_hint(&self) -> (usize, Option<usize>)
1865-
{
1856+
fn size_hint(&self) -> (usize, Option<usize>) {
18661857
self.iter.size_hint()
18671858
}
18681859
}
18691860

18701861
#[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> {
18731863
#[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 _)
18821868
}
1883-
}
1869+
)
18841870
}
18851871
}
18861872

18871873
#[unsafe_destructor]
18881874
#[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) {
18931877
// exhaust self first
18941878
while let Some(_) = self.next() { }
18951879

0 commit comments

Comments
 (0)