use std::path::Path;
use super::identity::TargetId;
use super::project::RustProject;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum RelativePathNormalizationError {
OutsideRoot,
NonUtf8,
}
pub fn normalize_relative_path(
root: &Path,
path: &Path,
) -> Result<Box<str>, RelativePathNormalizationError> {
super::super::path_normalization::relative_text(root, path).map_err(|error| match error {
super::super::path_normalization::RelativePathError::OutsideRoot => {
RelativePathNormalizationError::OutsideRoot
}
super::super::path_normalization::RelativePathError::NonUtf8 => {
RelativePathNormalizationError::NonUtf8
}
})
}
pub fn unknown_target_id(project: &RustProject) -> TargetId {
let index = u32::try_from(project.targets().len()).unwrap_or(u32::MAX);
TargetId::new(project.authority, index)
}