diff options
author | Alex Auvolat <alex@adnab.me> | 2020-11-20 20:11:04 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-11-20 20:11:04 +0100 |
commit | e9fd265ce6d326425994ccfea9d5afc7165460db (patch) | |
tree | 9dce56810d812d6b3293e20776b58bda91c05182 /src/table/util.rs | |
parent | b9e6b007a317bf307b209cf01667fa207d62b67d (diff) | |
download | garage-e9fd265ce6d326425994ccfea9d5afc7165460db.tar.gz garage-e9fd265ce6d326425994ccfea9d5afc7165460db.zip |
Slight refactoring to make things clearer with DeletedFilter
Diffstat (limited to 'src/table/util.rs')
-rw-r--r-- | src/table/util.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/table/util.rs b/src/table/util.rs new file mode 100644 index 00000000..043a457c --- /dev/null +++ b/src/table/util.rs @@ -0,0 +1,35 @@ +use serde::{Deserialize, Serialize}; + +use garage_util::data::*; + +use crate::schema::*; + +#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct EmptyKey; +impl SortKey for EmptyKey { + fn sort_key(&self) -> &[u8] { + &[] + } +} +impl PartitionKey for EmptyKey { + fn hash(&self) -> Hash { + [0u8; 32].into() + } +} + +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] +pub enum DeletedFilter { + All, + Deleted, + NotDeleted, +} + +impl DeletedFilter { + pub fn apply(&self, deleted: bool) -> bool { + match self { + DeletedFilter::All => true, + DeletedFilter::Deleted => deleted, + DeletedFilter::NotDeleted => !deleted, + } + } +} |