/*
    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,
        })
    }
}
