use std::borrow::Cow;
use std::ffi::OsStr;
use std::io::Result;
use std::path::Path;
use std::path::PathBuf;
pub fn maybe_parent<S: AsRef<OsStr> + ?Sized>(s: &S) -> &Path {
Path::new(s).parent().unwrap_or(Path::new(s))
}
pub trait PathExt {
fn normalize(&self) -> Result<PathBuf>;
fn absolutize(&self) -> Result<Cow<'_, Path>>;
fn absolutize_with(&self, cwd: &Path) -> Result<Cow<'_, Path>>;
}
impl PathExt for Path {
fn normalize(&self) -> Result<PathBuf> {
normpath::PathExt::normalize(self).map(|p| p.into_path_buf())
}
fn absolutize(&self) -> Result<Cow<'_, Path>> {
path_absolutize::Absolutize::absolutize(self)
}
fn absolutize_with(&self, cwd: &Path) -> Result<Cow<'_, Path>> {
path_absolutize::Absolutize::absolutize_from(self, cwd)
}
}