2025-02-08 17:27:20 -05:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
2025-02-08 18:01:59 -05:00
|
|
|
use crate::error::CustomError;
|
|
|
|
|
|
2025-02-08 17:27:20 -05:00
|
|
|
pub(crate) type RefDependencyManager = std::sync::Arc<std::sync::Mutex<DependencyManager>>;
|
|
|
|
|
|
|
|
|
|
#[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<PathBuf>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl DependencyManager {
|
|
|
|
|
pub(crate) fn new() -> Self {
|
|
|
|
|
DependencyManager {
|
|
|
|
|
file_stack: Vec::new(),
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-08 18:01:59 -05:00
|
|
|
|
|
|
|
|
pub(crate) fn push_file<P>(&mut self, path: P) -> Result<(), CustomError>
|
|
|
|
|
where
|
|
|
|
|
P: Into<PathBuf>,
|
|
|
|
|
{
|
|
|
|
|
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(())
|
|
|
|
|
}
|
2025-02-08 17:27:20 -05:00
|
|
|
}
|