Add a RelativePathBuf constructor which can construct a relative path from two std paths
While i tried to work around the bug, I found out that I can't use .relative() for absolute paths (which is expected):
called
Result::unwrap()on anErrvalue: FromPathError { kind: NonRelative }
But I belive it would be very useful if we can supply two absolute paths and get the RelativePath from it.
I could see us having another constructor which supports this:
let from = Path::new("/foo");
let to = Path::new("/foo/bar/baz");
let path = RelativePathBuf::relative_from(from, to)?;
This is a bit tricky to implement, and there are some choices that need to be made (what does it mean to build relative from two relative paths). But it's not fundamentally out of the question.
I second this. I just hit this problem in my code. Given a shared root, I want to calculate all RelativePaths to this root. Currently there is no other choice than to use std::PathBuf::strip_prefix, of which I'm not sure it works like I think it does.