fn subdir_of<'d, 'p>(d: &'d Dir, p: &'p Path) -> io::Result<(DirOwnedOrBorrowed<'d>, &'p OsStr)> {
    let name = p
        .file_name()
        .ok_or_else(|| std::io::Error::new(std::io::ErrorKind::InvalidInput, "Not a file name"))?;
    let r = if let Some(subdir) = p
        .parent()
        .filter(|v| !v.as_os_str().is_empty())
        .map(|p| d.open_dir(p))
    {
        DirOwnedOrBorrowed::Owned(subdir?)
    } else {
        DirOwnedOrBorrowed::Borrowed(d)
    };
    Ok((r, name))
}
/// Given a directory reference and a path, if the path includes a subdirectory (e.g. on Unix has a `/`)
/// then open up the target directory, and return the file name.
///
/// Otherwise, reborrow the directory and return the file name.
///
/// It is an error if the target path does not name a file.
Given a directory reference and a path, if the path includes a subdirectory
then open up the target directory, and return the file name.

Otherwise, reborrow the directory and return the file name.

It is an error if the target path does not name a file.
Given a directory reference and a path if the path includes a subdirectory then open up the target directory and return the file name . Otherwise reborrow the directory and return the file name . It is an error if the target path does not name a file .
fn subdir_of<'d, 'p>(d: &'d Dir, p: &'p Path) -> io::Result<(DirOwnedOrBorrowed<'d>, &'p OsStr)> {
    let name = p
        .file_name()
        .ok_or_else(|| std::io::Error::new(std::io::ErrorKind::InvalidInput, "Not a file name"))?;
    let r = if let Some(subdir) = p
        .parent()
        .filter(|v| !v.as_os_str().is_empty())
        .map(|p| d.open_dir(p))
    {
        DirOwnedOrBorrowed::Owned(subdir?)
    } else {
        DirOwnedOrBorrowed::Borrowed(d)
    };
    Ok((r, name))
}
fn subdir_of < ' d , ' p > ( d : & ' d Dir , p : & ' p Path ) -> io :: Result < ( DirOwnedOrBorrowed < ' d > , & ' p OsStr ) > { let name = p . file_name ( ) . ok_or_else ( | | std :: io :: Error :: new ( std :: io :: ErrorKind :: InvalidInput , " " ) ) ? ; let r = if let Some ( subdir ) = p . parent ( ) . filter ( | v | ! v . as_os_str ( ) . is_empty ( ) ) . map ( | p | d . open_dir ( p ) ) { DirOwnedOrBorrowed :: Owned ( subdir ? ) } else { DirOwnedOrBorrowed :: Borrowed ( d ) } ; Ok ( ( r , name ) ) }
Given a directory reference and a path, if the path includes a subdirectory (e.g.
Given a directory reference and a path if the path includes a subdirectory ( e . g .
d
&'d Dir
p
&'p Path
d
&'d Dir
p
&'p Path