Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/paths/src/lib.rs')
| -rw-r--r-- | crates/paths/src/lib.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/crates/paths/src/lib.rs b/crates/paths/src/lib.rs index 6ae23ac841..e0c20a4143 100644 --- a/crates/paths/src/lib.rs +++ b/crates/paths/src/lib.rs @@ -140,6 +140,11 @@ impl AbsPath { self.0.parent().map(AbsPath::assert) } + /// Equivalent of [`Path::join`] for `AbsPath` with an additional normalize step afterwards. + pub fn absolutize(&self, path: impl AsRef<Path>) -> AbsPathBuf { + self.join(path).normalize() + } + /// Equivalent of [`Path::join`] for `AbsPath`. pub fn join(&self, path: impl AsRef<Path>) -> AbsPathBuf { self.as_ref().join(path).try_into().unwrap() @@ -166,6 +171,10 @@ impl AbsPath { AbsPathBuf::try_from(self.0.to_path_buf()).unwrap() } + pub fn canonicalize(&self) -> ! { + panic!("We explicitly do not provide canonicalization API, as that is almost always a wrong solution, see #14430") + } + /// Equivalent of [`Path::strip_prefix`] for `AbsPath`. /// /// Returns a relative path. @@ -179,6 +188,13 @@ impl AbsPath { self.0.ends_with(&suffix.0) } + pub fn name_and_extension(&self) -> Option<(&str, Option<&str>)> { + Some(( + self.file_stem()?.to_str()?, + self.extension().and_then(|extension| extension.to_str()), + )) + } + // region:delegate-methods // Note that we deliberately don't implement `Deref<Target = Path>` here. |