Hey everyone,
I am looking for a good best-effort conversion of a relative to absolute file path.
So far I came up with an abomination using the shellexpand
crate and Path::canonicalize
. Plus it doesn't look like an idiomatic Rust to me.
fn abspath(p: &str) -> Option<String> {
shellexpand::full(p)
.ok()
.and_then(|x| Path::new(&x.into_owned()).canonicalize().ok())
.and_then(|x| x.into_os_string().into_string().ok())
}
Can this code be improved? I am not worried about symlinks and hardlinks for the moment.