Skip to content

Commit e1d5d1c

Browse files
author
blake2-ppc
committed
dlist: Use DoubleEndedIterator for .consume_rev_iter()
1 parent 89a0c99 commit e1d5d1c

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/libextra/dlist.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ pub struct ConsumeIterator<T> {
7272
priv list: DList<T>
7373
}
7474

75-
/// DList reverse consuming iterator
76-
pub struct ConsumeRevIterator<T> {
77-
priv list: DList<T>
78-
}
79-
8075
/// Rawlink is a type like Option<T> but for holding a raw pointer
8176
impl<T> Rawlink<T> {
8277
/// Like Option::None for Rawlink
@@ -346,8 +341,8 @@ impl<T> DList<T> {
346341
}
347342

348343
/// Consume the list into an iterator yielding elements by value, in reverse
349-
pub fn consume_rev_iter(self) -> ConsumeRevIterator<T> {
350-
ConsumeRevIterator{list: self}
344+
pub fn consume_rev_iter(self) -> InvertIterator<T, ConsumeIterator<T>> {
345+
self.consume_iter().invert()
351346
}
352347
}
353348

@@ -494,11 +489,8 @@ impl<A> Iterator<A> for ConsumeIterator<A> {
494489
}
495490
}
496491

497-
impl<A> Iterator<A> for ConsumeRevIterator<A> {
498-
fn next(&mut self) -> Option<A> { self.list.pop_back() }
499-
fn size_hint(&self) -> (uint, Option<uint>) {
500-
(self.list.length, Some(self.list.length))
501-
}
492+
impl<A> DoubleEndedIterator<A> for ConsumeIterator<A> {
493+
fn next_back(&mut self) -> Option<A> { self.list.pop_back() }
502494
}
503495

504496
impl<A, T: Iterator<A>> FromIterator<A, T> for DList<A> {

0 commit comments

Comments
 (0)