Skip to main content

path_relative

Function path_relative 

Source
pub fn path_relative<T: AsRef<Path>>(from: T, to: T) -> PathBuf
Expand description

Computes the relative path from one path to another.

This function takes two paths and returns a relative path from the from path to the to path. If the paths have different roots, the function returns the to path.

§Arguments

  • from - The starting path.
  • to - The target path.

§Returns

A std ::path ::PathBuf representing the relative path from from to to.

§Examples

use std ::path ::PathBuf;

let from = "/a/b";
let to = "/a/c/d";
let relative_path = pth ::path ::path_relative( from, to );
assert_eq!( relative_path, PathBuf ::from( "../c/d" ) );