diff options
author | Alex Auvolat <alex@adnab.me> | 2020-04-09 17:32:28 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-04-09 17:32:28 +0200 |
commit | 101444abb3967770ec378ee09f24eb2845dc091d (patch) | |
tree | 7bb838659014b47d220b27d95765174f5d0ae2fe /src/table.rs | |
parent | 4c1aee42d5032066272a051687ac200e874cc13f (diff) | |
download | garage-101444abb3967770ec378ee09f24eb2845dc091d.tar.gz garage-101444abb3967770ec378ee09f24eb2845dc091d.zip |
Some progress
Diffstat (limited to 'src/table.rs')
-rw-r--r-- | src/table.rs | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/src/table.rs b/src/table.rs index df82e9c7..55ae9229 100644 --- a/src/table.rs +++ b/src/table.rs @@ -64,11 +64,11 @@ pub struct Partition { pub other_nodes: Vec<UUID>, } -pub trait PartitionKey: Clone + PartialEq + Serialize + for<'de> Deserialize<'de> + Send + Sync { +pub trait PartitionKey { fn hash(&self) -> Hash; } -pub trait SortKey: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync { +pub trait SortKey { fn sort_key(&self) -> &[u8]; } @@ -87,33 +87,21 @@ impl SortKey for EmptySortKey { } } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct StringKey(String); -impl PartitionKey for StringKey { +impl<T: AsRef<str>> PartitionKey for T { fn hash(&self) -> Hash { - hash(self.0.as_bytes()) + hash(self.as_ref().as_bytes()) } } -impl SortKey for StringKey { +impl<T: AsRef<str>> SortKey for T { fn sort_key(&self) -> &[u8] { - self.0.as_bytes() - } -} -impl AsRef<str> for StringKey { - fn as_ref(&self) -> &str { - &self.0 - } -} -impl From<&str> for StringKey { - fn from(s: &str) -> StringKey { - StringKey(s.to_string()) + self.as_ref().as_bytes() } } #[async_trait] pub trait TableFormat: Send + Sync { - type P: PartitionKey; - type S: SortKey; + type P: PartitionKey + Clone + PartialEq + Serialize + for<'de> Deserialize<'de> + Send + Sync; + type S: SortKey + Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync; type E: Entry<Self::P, Self::S>; async fn updated(&self, old: Option<&Self::E>, new: &Self::E); |