Skip to main content

path_common

Function path_common 

Source
pub fn path_common<'a, I>(paths: I) -> Option<String>
where I: Iterator<Item = &'a str>,
Expand description

Finds the common directory path among a collection of paths.

Given an iterator of path strings, this function determines the common directory path shared by all paths. If no common directory path exists, it returns None.

§Arguments

  • paths - An iterator of path strings (&str).

§Returns

  • Option< String > - The common directory path shared by all paths, if it exists. If no common directory path exists, returns None.

§Examples

use pth ::path ::path_common;

let paths = vec![ "/a/b/c", "/a/b/d", "/a/b/e" ];
let common_path = path_common( paths.into_iter() );
assert_eq!( common_path, Some( "/a/b/".to_string() ) );