tinymist_package/pack/
ops.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use super::*;

/// A package in the directory.
pub struct FilterPack<'a, Src, F> {
    /// The files storing the package.
    pub(crate) src: &'a mut Src,
    /// The filter function to apply to each file.
    pub(crate) f: F,
}

impl<S: PackFs, F> fmt::Debug for FilterPack<'_, S, F> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "FilterPack({:?}, ..)", self.src)
    }
}
impl<Src: PackFs, F: Fn(&str) -> bool + Send + Sync> PackFs for FilterPack<'_, Src, F> {
    fn read_all(
        &mut self,
        f: &mut (dyn FnMut(&str, PackFile) -> PackageResult<()> + Send + Sync),
    ) -> PackageResult<()> {
        self.src.read_all(&mut |path, file| {
            if (self.f)(path) {
                f(path, file)
            } else {
                Ok(())
            }
        })
    }
}

impl<Src: PackFs, F: Fn(&str) -> bool + Send + Sync> Pack for FilterPack<'_, Src, F> {}