Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a RelativePathBuf constructor which can construct a relative path from two std paths #33

Open
Gordon01 opened this issue Dec 22, 2021 · 2 comments

Comments

@Gordon01
Copy link

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 an Err value: FromPathError { kind: NonRelative }

But I belive it would be very useful if we can supply two absolute paths and get the RelativePath from it.

@udoprog
Copy link
Owner

udoprog commented Mar 5, 2023

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.

@udoprog udoprog changed the title Relax .relative() restriction to allow using it on regular Path Add a RelativePathBuf constructor which can construct a relative path from two std paths Mar 5, 2023
@samvv
Copy link

samvv commented Feb 1, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants