Function pathsub::sub_paths

source ·
pub fn sub_paths(path: &Path, other: &Path) -> Option<PathBuf>
Expand description

Subtract other from path (in this order)

use pathsub::sub_paths;
use std::path::{Path, PathBuf};

let a = Path::new("foo/bar");
let b = Path::new("foo");
let c = Path::new("baz");
let d = Path::new(".").canonicalize().unwrap();

assert_eq!(sub_paths(a, b), Some(PathBuf::from("bar")));
assert_eq!(sub_paths(b, a), Some(PathBuf::from("")));
assert_eq!(sub_paths(a, c), None);
assert_eq!(sub_paths(a, &d), None);