blob: 9a735587fc2ced0b17eb324ff76d631fbc32beed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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) 2026 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,
})
}
}
|