diff options
author | Alex Auvolat <alex@adnab.me> | 2022-06-03 12:35:12 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-06-03 12:35:12 +0200 |
commit | 4bf706b170f149f54fd701576692cd5cd5bc9779 (patch) | |
tree | 9f85ddd71c76edfdbc7cfd0d016ae059bc5326e5 /src/db/lib.rs | |
parent | bd9ff432d716020d7235ece76257b60dc3ead95a (diff) | |
download | garage-4bf706b170f149f54fd701576692cd5cd5bc9779.tar.gz garage-4bf706b170f149f54fd701576692cd5cd5bc9779.zip |
Slightly prettier code
Diffstat (limited to 'src/db/lib.rs')
-rw-r--r-- | src/db/lib.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/db/lib.rs b/src/db/lib.rs index 1b31df43..045c16c5 100644 --- a/src/db/lib.rs +++ b/src/db/lib.rs @@ -226,6 +226,15 @@ impl Tree { self.0.len(self.1) } + pub fn first(&self) -> Result<Option<(Value<'_>, Value<'_>)>> { + self.iter()?.next().transpose() + } + pub fn get_gt<T: AsRef<[u8]>>(&self, from: T) -> Result<Option<(Value<'_>, Value<'_>)>> { + self.range((Bound::Excluded(from), Bound::Unbounded))? + .next() + .transpose() + } + pub fn insert<T: AsRef<[u8]>, U: AsRef<[u8]>>(&self, key: T, value: U) -> Result<()> { self.0.insert(self.1, key.as_ref(), value.as_ref()) } |