Rust 1.5.0 added std::fs::canonicalize , which sounds pretty close to what you want:
Returns the canonical form of the path with all normalized intermediate components and resolved symbolic links.
Note that unlike the accepted answer, this removes ./ from the returned path.
A simple example from my car:
use std::fs; use std::path::PathBuf; fn main() { let srcdir = PathBuf::from("./src"); println!("{:?}", fs::canonicalize(&srcdir)); let solardir = PathBuf::from("./../solarized/."); println!("{:?}", fs::canonicalize(&solardir)); }
Ok("/Users/alexwlchan/Developer/so-example/src") Ok("/Users/alexwlchan/Developer/solarized")
alexwlchan
source share