tinymist_package/pack/
ops.rs

1use super::*;
2
3/// A package in the directory.
4pub struct FilterPack<'a, Src, F> {
5    /// The files storing the package.
6    pub(crate) src: &'a mut Src,
7    /// The filter function to apply to each file.
8    pub(crate) f: F,
9}
10
11impl<S: PackFs, F> fmt::Debug for FilterPack<'_, S, F> {
12    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13        write!(f, "FilterPack({:?}, ..)", self.src)
14    }
15}
16impl<Src: PackFs, F: Fn(&str) -> bool + Send + Sync> PackFs for FilterPack<'_, Src, F> {
17    fn read_all(
18        &mut self,
19        f: &mut (dyn FnMut(&str, PackFile) -> PackageResult<()> + Send + Sync),
20    ) -> PackageResult<()> {
21        self.src.read_all(&mut |path, file| {
22            if (self.f)(path) {
23                f(path, file)
24            } else {
25                Ok(())
26            }
27        })
28    }
29}
30
31impl<Src: PackFs, F: Fn(&str) -> bool + Send + Sync> Pack for FilterPack<'_, Src, F> {}