use std::path::Path; use std::path::PathBuf; use crate::error::CustomError; use super::dependency::Dependency; pub(crate) type RefDependencyManager = std::sync::Arc>; #[derive(Debug)] pub(crate) struct DependencyManager { /// A stack of paths for the files being visited. /// /// The last entry is the current file being processed. This can be used for handling relative-path links. file_stack: Vec, dependencies: Vec, } impl DependencyManager { pub(crate) fn new() -> Self { DependencyManager { file_stack: Vec::new(), dependencies: Vec::new(), } } pub(crate) fn push_file

(&mut self, path: P) -> Result<(), CustomError> where P: Into, { self.file_stack.push(path.into()); Ok(()) } pub(crate) fn pop_file(&mut self) -> Result<(), CustomError> { self.file_stack .pop() .expect("Popped more files off the dependency manager file stack than exist."); Ok(()) } pub(crate) fn get_current_folder(&self) -> Result<&Path, CustomError> { Ok(self .file_stack .last() .ok_or("No current file")? .parent() .ok_or("Current file was not in a directory")?) } pub(crate) fn mark_file_for_copying

(&mut self, path: P) -> Result<(), CustomError> where P: Into, { self.dependencies.push(Dependency::StaticFile { absolute_path: path.into(), }); Ok(()) } /// Return the dependencies and forget about them. pub(crate) fn take_dependencies(&mut self) -> Vec { let mut dependencies = Vec::new(); std::mem::swap(&mut self.dependencies, &mut dependencies); dependencies } }