changeset 42:85e3fb6bf1b8

Implement PartialOrd for Record
author Lewin Bormann <lbo@spheniscida.de>
date Mon, 01 Feb 2016 20:54:42 +0000
parents 2ec1d193c8f0
children ab7d19e012e0
files src/mapreducer.rs
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/mapreducer.rs	Mon Feb 01 20:41:45 2016 +0000
+++ b/src/mapreducer.rs	Mon Feb 01 20:54:42 2016 +0000
@@ -1,15 +1,26 @@
 //! The MapReducer trait and associated types.
 
+use std::clone::Clone;
+use std::cmp::{PartialOrd, Eq, Ordering};
 use std::collections::LinkedList;
-use std::clone::Clone;
 use std::hash::{Hasher, SipHasher};
 
 /// A (key,value) pair.
+#[derive(Clone, PartialEq, Eq)]
 pub struct Record {
     pub key: String,
     pub value: String,
 }
 
+impl PartialOrd for Record {
+    fn partial_cmp(&self, other: &Record) -> Option<Ordering> {
+        match self.key.cmp(&other.key) {
+            Ordering::Equal => Some(self.value.cmp(&other.value)),
+            o => Some(o)
+        }
+    }
+}
+
 /// A (key,[value]) pair; typicall used as input to a reducer function.
 /// Can be easily iterated over, e.g. in a `for` loop.
 pub struct MultiRecord {