changeset 10:3f35e5705cc2

Make RecordIterator a generic type Damn, I'm just too Gopher for Rust
author Lewin Bormann <lbo@spheniscida.de>
date Sat, 30 Jan 2016 22:18:15 +0000
parents 020bfec8699f
children 252068bd2a8b
files src/formats/writelog.rs src/util.rs
diffstat 2 files changed, 10 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/formats/writelog.rs	Sat Jan 30 22:01:54 2016 +0000
+++ b/src/formats/writelog.rs	Sat Jan 30 22:18:15 2016 +0000
@@ -203,11 +203,11 @@
 }
 
 /// Iterator type for WriteLogReader; used to implement IntoIterator
-struct WLRIteratorAdapter {
+pub struct IntoIter {
     wlr: WriteLogReader,
 }
 
-impl Iterator for WLRIteratorAdapter {
+impl Iterator for IntoIter {
     type Item = String;
     fn next(&mut self) -> Option<String> {
         let result = self.wlr.read_vec();
@@ -227,9 +227,9 @@
 
 impl IntoIterator for WriteLogReader {
     type Item = Record;
-    type IntoIter = RecordIterator;
-    fn into_iter(self) -> RecordIterator {
-        RecordIterator::new(Box::new(WLRIteratorAdapter{ wlr: self }))
+    type IntoIter = RecordIterator<IntoIter>;
+    fn into_iter(self) -> Self::IntoIter {
+        RecordIterator::new(IntoIter{ wlr: self })
     }
 }
 
--- a/src/util.rs	Sat Jan 30 22:01:54 2016 +0000
+++ b/src/util.rs	Sat Jan 30 22:18:15 2016 +0000
@@ -5,18 +5,18 @@
 /// records with the key being the position of the current record, starting with
 /// 1. Mainly used as input iterator in the mapping phase, from sources that only
 /// yield values (no keys).
-pub struct RecordIterator {
-    i: Box<Iterator<Item=String>>,
+pub struct RecordIterator<I: Iterator<Item=String>> {
+    i: I,
     counter: u64,
 }
 
-impl RecordIterator {
-    pub fn new(it: Box<Iterator<Item=String>>) -> RecordIterator {
+impl<I: Iterator<Item=String>> RecordIterator<I> {
+    pub fn new(it: I) -> RecordIterator<I> {
         RecordIterator { i: it, counter: 0 }
     }
 }
 
-impl Iterator for RecordIterator {
+impl<I: Iterator<Item=String>> Iterator for RecordIterator<I> {
     type Item = Record;
     fn next(&mut self) -> Option<Record> {
         match self.i.next() {