common_path

Function common_path

Source
pub fn common_path<P, Q>(one: P, two: Q) -> Option<PathBuf>
where P: AsRef<Path>, Q: AsRef<Path>,
Expand description

Find the common prefix, if any, between 2 paths

ยงExample

use std::path::{PathBuf, Path};
use common_path::common_path;

let baz = Path::new("/foo/bar/baz");
let quux = Path::new("/foo/bar/quux");
let prefix = common_path(baz, quux).unwrap();
assert_eq!(prefix, Path::new("/foo/bar").to_path_buf());