aware-tectonic 0.16.10

A modernized, complete, embeddable TeX/LaTeX engine. Tectonic is forked from the XeTeX extension to the classic "Web2C" implementation of TeX and uses the TeXLive distribution of support files. This is the Aware Software fork of tectonic 0.16.9: identical to upstream except that its bundle crate (aware-tectonic-bundles) does not contact the network when the bundle cache is warm.
Documentation
use super::BundleInput;
use anyhow::Result;
use std::{
    fs::{self},
    io::Read,
    path::PathBuf,
};
use walkdir::WalkDir;

pub struct DirBundleInput {
    dir: PathBuf,
}

impl DirBundleInput {
    pub fn new(dir: PathBuf) -> Self {
        Self {
            dir: dir.canonicalize().unwrap(),
        }
    }
}

impl BundleInput for DirBundleInput {
    fn iter_files(&mut self) -> impl Iterator<Item = Result<(String, Box<dyn Read + '_>)>> {
        WalkDir::new(&self.dir)
            .into_iter()
            .filter_map(|x| match x {
                Err(_) => Some(x),
                Ok(x) => {
                    if !x.file_type().is_file() {
                        None
                    } else {
                        Some(Ok(x))
                    }
                }
            })
            .map(move |x| match x {
                Ok(x) => {
                    let path = x
                        .into_path()
                        .canonicalize()
                        .unwrap()
                        .strip_prefix(&self.dir)
                        .unwrap()
                        .to_str()
                        .unwrap()
                        .to_string();

                    Ok((
                        path.clone(),
                        Box::new(fs::File::open(self.dir.join(path))?) as Box<dyn Read>,
                    ))
                }
                Err(e) => Err(anyhow::Error::from(e)),
            })
    }
}