aboutsummaryrefslogtreecommitdiff
path: root/src/table/schema.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-11-20 20:11:04 +0100
committerAlex Auvolat <alex@adnab.me>2020-11-20 20:11:04 +0100
commite9fd265ce6d326425994ccfea9d5afc7165460db (patch)
tree9dce56810d812d6b3293e20776b58bda91c05182 /src/table/schema.rs
parentb9e6b007a317bf307b209cf01667fa207d62b67d (diff)
downloadgarage-e9fd265ce6d326425994ccfea9d5afc7165460db.tar.gz
garage-e9fd265ce6d326425994ccfea9d5afc7165460db.zip
Slight refactoring to make things clearer with DeletedFilter
Diffstat (limited to 'src/table/schema.rs')
-rw-r--r--src/table/schema.rs51
1 files changed, 22 insertions, 29 deletions
diff --git a/src/table/schema.rs b/src/table/schema.rs
index 1914320e..49cede0a 100644
--- a/src/table/schema.rs
+++ b/src/table/schema.rs
@@ -8,54 +8,46 @@ pub trait PartitionKey {
fn hash(&self) -> Hash;
}
-pub trait SortKey {
- fn sort_key(&self) -> &[u8];
-}
-
-pub trait Entry<P: PartitionKey, S: SortKey>:
- PartialEq + Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync
-{
- fn partition_key(&self) -> &P;
- fn sort_key(&self) -> &S;
-
- fn merge(&mut self, other: &Self);
-}
-
-#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
-pub struct EmptyKey;
-impl SortKey for EmptyKey {
- fn sort_key(&self) -> &[u8] {
- &[]
- }
-}
-impl PartitionKey for EmptyKey {
+impl PartitionKey for String {
fn hash(&self) -> Hash {
- [0u8; 32].into()
+ hash(self.as_bytes())
}
}
-impl PartitionKey for String {
+impl PartitionKey for Hash {
fn hash(&self) -> Hash {
- hash(self.as_bytes())
+ self.clone()
}
}
+
+
+pub trait SortKey {
+ fn sort_key(&self) -> &[u8];
+}
+
impl SortKey for String {
fn sort_key(&self) -> &[u8] {
self.as_bytes()
}
}
-impl PartitionKey for Hash {
- fn hash(&self) -> Hash {
- self.clone()
- }
-}
impl SortKey for Hash {
fn sort_key(&self) -> &[u8] {
self.as_slice()
}
}
+
+pub trait Entry<P: PartitionKey, S: SortKey>:
+ PartialEq + Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync
+{
+ fn partition_key(&self) -> &P;
+ fn sort_key(&self) -> &S;
+
+ fn merge(&mut self, other: &Self);
+}
+
+
#[async_trait]
pub trait TableSchema: Send + Sync {
type P: PartitionKey + Clone + PartialEq + Serialize + for<'de> Deserialize<'de> + Send + Sync;
@@ -74,3 +66,4 @@ pub trait TableSchema: Send + Sync {
true
}
}
+