fix(els): use NormalizedPathBuf for AbsLocation

This commit is contained in:
Shunsuke Shibayama 2023-09-13 23:26:05 +09:00
parent 138c6ff3d8
commit 38f44e8d31
10 changed files with 40 additions and 14 deletions

View file

@ -174,7 +174,7 @@ impl ErgConfig {
if let Some(output) = &self.dist_dir {
PathBuf::from(format!("{output}/{}", self.input.filename()))
} else {
self.input.full_path()
self.input.full_path().to_path_buf()
}
}

View file

@ -245,6 +245,7 @@ impl Input {
}
}
/// This is not normalized, so use `NormalizedPathBuf::new` to compare
pub fn path(&self) -> &Path {
self.kind.path()
}

View file

@ -1,5 +1,6 @@
use std::borrow::Borrow;
use std::ffi::OsStr;
use std::fmt;
use std::ops::Deref;
use std::path::{Component, Path, PathBuf};
@ -13,12 +14,24 @@ use crate::normalize_path;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
pub struct NormalizedPathBuf(PathBuf);
impl fmt::Display for NormalizedPathBuf {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.display())
}
}
impl<P: Into<PathBuf>> From<P> for NormalizedPathBuf {
fn from(path: P) -> Self {
NormalizedPathBuf::new(path.into())
}
}
impl AsRef<Path> for NormalizedPathBuf {
fn as_ref(&self) -> &Path {
self.0.as_path()
}
}
impl Borrow<PathBuf> for NormalizedPathBuf {
fn borrow(&self) -> &PathBuf {
&self.0
@ -43,6 +56,14 @@ impl NormalizedPathBuf {
pub fn new(path: PathBuf) -> Self {
NormalizedPathBuf(normalize_path(path.canonicalize().unwrap_or(path)))
}
pub fn as_path(&self) -> &Path {
self.0.as_path()
}
pub fn to_path_buf(&self) -> PathBuf {
self.0.clone()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]