changeset 11:252068bd2a8b

Move RecordIterator to formats/
author Lewin Bormann <lbo@spheniscida.de>
date Sun, 31 Jan 2016 11:37:53 +0000
parents 3f35e5705cc2
children 86b39697bc0e
files src/formats/util.rs src/util.rs
diffstat 2 files changed, 30 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/formats/util.rs	Sun Jan 31 11:37:53 2016 +0000
@@ -0,0 +1,30 @@
+use mapreducer::Record;
+use std::fmt;
+
+/// Transforms an iterator<string> into an iterator<Record>. It yields
+/// 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: Iterator<Item=String>> {
+    i: I,
+    counter: u64,
+}
+
+impl<I: Iterator<Item=String>> RecordIterator<I> {
+    pub fn new(it: I) -> RecordIterator<I> {
+        RecordIterator { i: it, counter: 0 }
+    }
+}
+
+impl<I: Iterator<Item=String>> Iterator for RecordIterator<I> {
+    type Item = Record;
+    fn next(&mut self) -> Option<Record> {
+        match self.i.next() {
+            None => None,
+            Some(val) => {
+                self.counter += 1;
+                Some(Record { key: fmt::format(format_args!("{}", self.counter)), value: val })
+            }
+        }
+    }
+}
--- a/src/util.rs	Sat Jan 30 22:18:15 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-use mapreducer::Record;
-use std::fmt;
-
-/// Transforms an iterator<string> into an iterator<Record>. It yields
-/// 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: Iterator<Item=String>> {
-    i: I,
-    counter: u64,
-}
-
-impl<I: Iterator<Item=String>> RecordIterator<I> {
-    pub fn new(it: I) -> RecordIterator<I> {
-        RecordIterator { i: it, counter: 0 }
-    }
-}
-
-impl<I: Iterator<Item=String>> Iterator for RecordIterator<I> {
-    type Item = Record;
-    fn next(&mut self) -> Option<Record> {
-        match self.i.next() {
-            None => None,
-            Some(val) => {
-                self.counter += 1;
-                Some(Record { key: fmt::format(format_args!("{}", self.counter)), value: val })
-            }
-        }
-    }
-}