aboutsummaryrefslogtreecommitdiff
path: root/database/src/prefix_iterator.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-12-24 09:02:17 +0100
committermetamuffin <metamuffin@disroot.org>2025-12-24 09:02:17 +0100
commitd543f6fe11a32dcead2310f1fb4c2abd303f5f8c (patch)
tree3ba8274f0906250809ca5fa1b08c9b5f53b88cc7 /database/src/prefix_iterator.rs
parenteac0de36221440571fe686074b04b71bf98cf727 (diff)
downloadjellything-d543f6fe11a32dcead2310f1fb4c2abd303f5f8c.tar
jellything-d543f6fe11a32dcead2310f1fb4c2abd303f5f8c.tar.bz2
jellything-d543f6fe11a32dcead2310f1fb4c2abd303f5f8c.tar.zst
db abstraction looks good
Diffstat (limited to 'database/src/prefix_iterator.rs')
-rw-r--r--database/src/prefix_iterator.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/database/src/prefix_iterator.rs b/database/src/prefix_iterator.rs
new file mode 100644
index 0000000..3586ae2
--- /dev/null
+++ b/database/src/prefix_iterator.rs
@@ -0,0 +1,22 @@
+/*
+ This file is part of jellything (https://codeberg.org/metamuffin/jellything)
+ which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
+ Copyright (C) 2025 metamuffin <metamuffin.org>
+*/
+
+use anyhow::Result;
+use std::borrow::Cow;
+
+pub struct PrefixIterator<'a> {
+ pub inner: Box<dyn Iterator<Item = Result<Vec<u8>>> + 'a>,
+ pub prefix: Cow<'a, [u8]>,
+}
+impl Iterator for PrefixIterator<'_> {
+ type Item = Result<Vec<u8>>;
+ fn next(&mut self) -> Option<Self::Item> {
+ self.inner.next().filter(|k| match k {
+ Ok(v) => v.starts_with(&self.prefix),
+ Err(_) => true,
+ })
+ }
+}