Make store::Row sortable (by key) and clonable

This commit is contained in:
Roman Zeyde 2018-07-09 19:07:33 +03:00
parent baf2d8624d
commit 45f3c7d178
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB

View File

@ -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<Ordering> {
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<Bytes>;
fn scan(&self, prefix: &[u8]) -> Vec<Row>;