From 45f3c7d178eb4a9ec351429faac069b9ee3ca18a Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Mon, 9 Jul 2018 19:07:33 +0300 Subject: [PATCH] Make store::Row sortable (by key) and clonable --- src/store.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/store.rs b/src/store.rs index 096f41c..74365ad 100644 --- a/src/store.rs +++ b/src/store.rs @@ -1,10 +1,12 @@ use rocksdb; use rocksdb::Writable; +use std::cmp::Ordering; use std::path::Path; use util::Bytes; +#[derive(Clone)] pub struct Row { pub key: Bytes, pub value: Bytes, @@ -16,6 +18,26 @@ impl Row { } } +impl Ord for Row { + fn cmp(&self, other: &Row) -> Ordering { + self.key.cmp(&other.key) + } +} + +impl PartialOrd for Row { + fn partial_cmp(&self, other: &Row) -> Option { + Some(self.cmp(other)) + } +} + +impl PartialEq for Row { + fn eq(&self, other: &Row) -> bool { + self.key.eq(&other.key) + } +} + +impl Eq for Row {} + pub trait ReadStore: Sync { fn get(&self, key: &[u8]) -> Option; fn scan(&self, prefix: &[u8]) -> Vec;