mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 04:09:05 +00:00
fix(els): use NormalizedPathBuf
for AbsLocation
This commit is contained in:
parent
138c6ff3d8
commit
38f44e8d31
10 changed files with 40 additions and 14 deletions
|
@ -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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue