use crate::PackageIndex;
pub(super) fn normalized_path(crate_: &PackageIndex<'_>, path: &rustdoc_types::Path) -> String {
if crate_.own_crate.inner.index.contains_key(&path.id) {
let importable_paths = crate_.own_crate.publicly_importable_names(&path.id);
let importable_path = importable_paths.iter().min_by_key(|importable_path| {
(
!importable_path.public_api(),
importable_path.modifiers.unstable,
importable_path.modifiers.doc_hidden,
importable_path.modifiers.deprecated,
)
});
if let Some(importable_path) = importable_path {
return absolute_path(importable_path.path.components.iter().copied());
}
}
if let Some(summary) = crate_.own_crate.inner.paths.get(&path.id) {
return absolute_path(summary.path.iter().map(String::as_str));
}
assert_ne!(path.path, "");
if path.path.starts_with("::") {
path.path.clone()
} else {
format!("::{}", path.path)
}
}
fn absolute_path<'a>(components: impl ExactSizeIterator<Item = &'a str>) -> String {
let length = components.len();
let mut output = String::with_capacity(10 * length);
for component in components {
output.push_str("::");
output.push_str(component);
}
output
}