get_common_path

Function get_common_path 

Source
pub fn get_common_path<T: Debug + Display>(
    arg_slice_of_strings: &[T],
) -> Result<String, String>
Expand description

Returns a string path which is shared between all paths in the slice of string-like values If the common path doesn’t exist, the function will then iterate upwards through the common path’s ancestors until to a path is found, or no further parents exist. Returns None in case of failure (either no match found, nothing about the common string exists)

§Arguments

  • arg_slice_of_strings: slice of string-like paths

§Examples

let slice_of_strings = [ “/A/B”, “/A/B/C”, “/A/B/C/D”, ]; let result = match get_common_path( &slice_of_strings ) { Ok( string_result ) => { string_result } Err( err ) => { panic!( “{}”, err ) } }; // If ‘/A/B’ exists, then that is the common shared path and the function will return this // If ‘/A’ exists, but ‘/A/B’ is actually fictitious, then the function will continue // fetching the ‘parent’ directory until it finds one that exists. In this scenario, that // directory would be ‘/A’