Mercurial > lbo > hg > localmr
changeset 14:895d6a1771db
Run cargo fmt
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sun, 31 Jan 2016 11:40:30 +0000 |
parents | 1761ff21fedd |
children | 8a15fbf8589f |
files | src/closure_mr.rs src/formats/util.rs src/formats/writelog.rs src/lib.rs src/mapreducer.rs |
diffstat | 5 files changed, 56 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/src/closure_mr.rs Sun Jan 31 11:40:13 2016 +0000 +++ b/src/closure_mr.rs Sun Jan 31 11:40:30 2016 +0000 @@ -1,12 +1,4 @@ -use mapreducer::{ - MEmitter, - MapReducer, - MapperF, - MultiRecord, - REmitter, - Record, - ReducerF, -}; +use mapreducer::{MEmitter, MapReducer, MapperF, MultiRecord, REmitter, Record, ReducerF}; struct ClosureMapReducer { mapper: MapperF, @@ -15,17 +7,27 @@ impl Clone for ClosureMapReducer { fn clone(&self) -> ClosureMapReducer { - ClosureMapReducer { mapper: self.mapper, reducer: self.reducer } + ClosureMapReducer { + mapper: self.mapper, + reducer: self.reducer, + } } } impl ClosureMapReducer { pub fn new(mapper: MapperF, reducer: ReducerF) -> ClosureMapReducer { - ClosureMapReducer { mapper: mapper, reducer: reducer } + ClosureMapReducer { + mapper: mapper, + reducer: reducer, + } } } impl MapReducer for ClosureMapReducer { - fn map(&self, e: &mut MEmitter, r: Record) { (self.mapper)(e, r) } - fn reduce(&self, e: &mut REmitter, r: MultiRecord) { (self.reducer)(e, r) } + fn map(&self, e: &mut MEmitter, r: Record) { + (self.mapper)(e, r) + } + fn reduce(&self, e: &mut REmitter, r: MultiRecord) { + (self.reducer)(e, r) + } }
--- a/src/formats/util.rs Sun Jan 31 11:40:13 2016 +0000 +++ b/src/formats/util.rs Sun Jan 31 11:40:30 2016 +0000 @@ -5,25 +5,31 @@ /// 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>> { +pub struct RecordIterator<I: Iterator<Item = String>> { i: I, counter: u64, } -impl<I: Iterator<Item=String>> RecordIterator<I> { +impl<I: Iterator<Item = String>> RecordIterator<I> { pub fn new(it: I) -> RecordIterator<I> { - RecordIterator { i: it, counter: 0 } + RecordIterator { + i: it, + counter: 0, + } } } -impl<I: Iterator<Item=String>> Iterator for RecordIterator<I> { +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 }) + Some(Record { + key: fmt::format(format_args!("{}", self.counter)), + value: val, + }) } } }
--- a/src/formats/writelog.rs Sun Jan 31 11:40:13 2016 +0000 +++ b/src/formats/writelog.rs Sun Jan 31 11:40:30 2016 +0000 @@ -135,17 +135,27 @@ for entry in dir { let name; match entry { - Err(e) => { println!("Error opening {}: {}", path, e); continue }, - Ok(direntry) => name = direntry.path() + Err(e) => { + println!("Error opening {}: {}", path, e); + continue; + } + Ok(direntry) => name = direntry.path(), } if name.ends_with(suffix) { match fs::OpenOptions::new().read(true).open(name.clone()) { - Err(e) => { println!("Error opening {:?}: {}", name, e); continue }, - Ok(f) => reader = Box::new(reader.chain(f)) + Err(e) => { + println!("Error opening {:?}: {}", name, e); + continue; + } + Ok(f) => reader = Box::new(reader.chain(f)), } } } - Ok(WriteLogReader{ src: reader, records_read: 0, bytes_read: 0 }) + Ok(WriteLogReader { + src: reader, + records_read: 0, + bytes_read: 0, + }) } pub fn get_stats(&self) -> (u32, usize) { @@ -215,12 +225,12 @@ match result { Err(_) => return None, - Ok(v) => convert_result = string::String::from_utf8(v) + Ok(v) => convert_result = string::String::from_utf8(v), } match convert_result { Err(_) => None, - Ok(s) => Some(s) + Ok(s) => Some(s), } } } @@ -229,7 +239,7 @@ type Item = Record; type IntoIter = RecordIterator<IntoIter>; fn into_iter(self) -> Self::IntoIter { - RecordIterator::new(IntoIter{ wlr: self }) + RecordIterator::new(IntoIter { wlr: self }) } }
--- a/src/lib.rs Sun Jan 31 11:40:13 2016 +0000 +++ b/src/lib.rs Sun Jan 31 11:40:30 2016 +0000 @@ -3,5 +3,4 @@ pub mod mapreducer; #[test] -fn it_works() { -} +fn it_works() {}
--- a/src/mapreducer.rs Sun Jan 31 11:40:13 2016 +0000 +++ b/src/mapreducer.rs Sun Jan 31 11:40:30 2016 +0000 @@ -9,7 +9,7 @@ /// Input to a reducer function. pub struct MultiRecord { key: String, - value: Box<Iterator<Item=String>>, + value: Box<Iterator<Item = String>>, } impl MultiRecord { @@ -37,9 +37,14 @@ MEmitter { r: LinkedList::new() } } pub fn emit(&mut self, key: String, val: String) { - self.r.push_back(Record { key: key, value: val }) + self.r.push_back(Record { + key: key, + value: val, + }) } - pub fn _get(self) -> LinkedList<Record> { self.r } + pub fn _get(self) -> LinkedList<Record> { + self.r + } } pub struct REmitter { @@ -53,7 +58,9 @@ pub fn emit(&mut self, val: String) { self.r.push_back(val) } - pub fn _get(self) -> LinkedList<String> { self.r } + pub fn _get(self) -> LinkedList<String> { + self.r + } } pub type MapperF = fn(&mut MEmitter, Record); @@ -66,4 +73,3 @@ fn map(&self, em: &mut MEmitter, record: Record); fn reduce(&self, em: &mut REmitter, records: MultiRecord); } -