2024-01-08 13:26:33 -08:00
|
|
|
use super::*;
|
|
|
|
|
2024-05-19 02:29:13 -07:00
|
|
|
#[derive(Debug)]
|
2024-01-08 13:26:33 -08:00
|
|
|
pub(crate) struct Source<'src> {
|
2024-05-18 23:38:57 -07:00
|
|
|
pub(crate) file_depth: u32,
|
2024-01-08 13:26:33 -08:00
|
|
|
pub(crate) namepath: Namepath<'src>,
|
2024-05-18 23:38:57 -07:00
|
|
|
pub(crate) path: PathBuf,
|
|
|
|
pub(crate) submodule_depth: u32,
|
2024-01-11 19:00:38 -08:00
|
|
|
pub(crate) working_directory: PathBuf,
|
2024-01-08 13:26:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'src> Source<'src> {
|
|
|
|
pub(crate) fn root(path: &Path) -> Self {
|
|
|
|
Self {
|
2024-05-18 23:38:57 -07:00
|
|
|
file_depth: 0,
|
2024-01-08 13:26:33 -08:00
|
|
|
namepath: Namepath::default(),
|
2024-05-18 23:38:57 -07:00
|
|
|
path: path.into(),
|
|
|
|
submodule_depth: 0,
|
2024-01-11 19:00:38 -08:00
|
|
|
working_directory: path.parent().unwrap().into(),
|
2024-01-08 13:26:33 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn import(&self, path: PathBuf) -> Self {
|
|
|
|
Self {
|
2024-05-18 23:38:57 -07:00
|
|
|
file_depth: self.file_depth + 1,
|
2024-01-08 13:26:33 -08:00
|
|
|
namepath: self.namepath.clone(),
|
2024-05-18 23:38:57 -07:00
|
|
|
path,
|
|
|
|
submodule_depth: self.submodule_depth,
|
2024-01-11 19:00:38 -08:00
|
|
|
working_directory: self.working_directory.clone(),
|
2024-01-08 13:26:33 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn module(&self, name: Name<'src>, path: PathBuf) -> Self {
|
|
|
|
Self {
|
2024-05-18 23:38:57 -07:00
|
|
|
file_depth: self.file_depth + 1,
|
|
|
|
namepath: self.namepath.join(name),
|
|
|
|
submodule_depth: self.submodule_depth + 1,
|
2024-01-11 19:00:38 -08:00
|
|
|
working_directory: path.parent().unwrap().into(),
|
2024-01-08 13:26:33 -08:00
|
|
|
path,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|