pedant_core/resolution/rust/
test_support.rs1use std::path::Path;
4
5use super::identity::TargetId;
6use super::project::RustProject;
7
8#[derive(Clone, Copy, Debug, Eq, PartialEq)]
10pub enum RelativePathNormalizationError {
11 OutsideRoot,
13 NonUtf8,
15}
16
17pub fn normalize_relative_path(
20 root: &Path,
21 path: &Path,
22) -> Result<Box<str>, RelativePathNormalizationError> {
23 super::super::path_normalization::relative_text(root, path).map_err(|error| match error {
24 super::super::path_normalization::RelativePathError::OutsideRoot => {
25 RelativePathNormalizationError::OutsideRoot
26 }
27 super::super::path_normalization::RelativePathError::NonUtf8 => {
28 RelativePathNormalizationError::NonUtf8
29 }
30 })
31}
32
33pub fn unknown_target_id(project: &RustProject) -> TargetId {
40 let index = u32::try_from(project.targets().len()).unwrap_or(u32::MAX);
41 TargetId::new(project.authority, index)
42}