use std::path::{Component, PathBuf}; pub fn canon_path_str(path: impl AsRef) -> String { let p = path.as_ref(); let mut normalized = PathBuf::new(); for component in p.components() { match component { Component::Prefix(p) => normalized.push(p.as_os_str()), Component::RootDir => normalized.push("/"), Component::CurDir => {} Component::ParentDir => { normalized.pop(); } Component::Normal(c) => normalized.push(c), } } normalized.to_string_lossy().into_owned() }