1

I'd like to return the relative path from an absolute path.

E.g.:

use std::path::PathBuf;

fn main() {
    let any_path = PathBuf::from("/abc/def/foo/bar".to_string());
    let current = PathBuf::from("/abc/def/here".to_string());
    
    println!("The relative path is: {:?}", make_relative(&any_path, &current));
}

The function make_relative should do that work in order to have this output:

The relative path is: "../foo/bar"
vallentin
  • 23,478
  • 6
  • 59
  • 81
Corebreaker
  • 357
  • 1
  • 11
  • 1
    @vallentin `pathdiff::diff_paths(&any_path, &current)` => `Some("../foo/bar")` ? Do you mean the `Some`? I'm sure the OP can find their way to `Option::unwrap`. – Shepmaster Jan 06 '21 at 18:26
  • @Shepmaster I already removed the comment, I skimmed too quickly and only interpreted `Path::strip_prefix` :) – vallentin Jan 06 '21 at 18:30

0 Answers0