|
|
@ -1,10 +1,11 @@ |
|
|
|
|
|
|
|
use std::ffi::OsStr; |
|
|
|
use std::path::Path; |
|
|
|
use std::path::Path; |
|
|
|
|
|
|
|
|
|
|
|
fn extract<'a>( |
|
|
|
fn extract<'a>( |
|
|
|
path: &'a Path, |
|
|
|
path: &'a Path, |
|
|
|
current_name: Option<&'a str>, |
|
|
|
current_name: Option<&'a str>, |
|
|
|
) -> Option<(&'a Path, Option<&'a str>)> { |
|
|
|
) -> Option<(&'a Path, Option<&'a str>)> { |
|
|
|
let name = path.file_name().map(|x| x.to_str()).flatten(); |
|
|
|
let name = path.file_name().map(OsStr::to_str).flatten(); |
|
|
|
let parent = path.parent()?; |
|
|
|
let parent = path.parent()?; |
|
|
|
|
|
|
|
|
|
|
|
// println!("path={path:?}, current_name={current_name:?}, parent={parent:?}, name={name:?}");
|
|
|
|
// println!("path={path:?}, current_name={current_name:?}, parent={parent:?}, name={name:?}");
|
|
|
@ -30,7 +31,7 @@ mod test { |
|
|
|
assert_eq!(result.0, Path::new("something")); |
|
|
|
assert_eq!(result.0, Path::new("something")); |
|
|
|
assert_eq!(result.1, Some("default")); |
|
|
|
assert_eq!(result.1, Some("default")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn child() { |
|
|
|
fn child() { |
|
|
|
let result = extract(Path::new("something/.run/special/path"), None).unwrap(); |
|
|
|
let result = extract(Path::new("something/.run/special/path"), None).unwrap(); |
|
|
|