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.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/crates/paths/src/lib.rs b/crates/paths/src/lib.rs
index 2d3653401d..33c3f83db5 100644
--- a/crates/paths/src/lib.rs
+++ b/crates/paths/src/lib.rs
@@ -106,7 +106,7 @@ impl AbsPathBuf {
/// Panics if `path` is not absolute.
pub fn assert(path: Utf8PathBuf) -> AbsPathBuf {
AbsPathBuf::try_from(path)
- .unwrap_or_else(|path| panic!("expected absolute path, got {}", path))
+ .unwrap_or_else(|path| panic!("expected absolute path, got {path}"))
}
/// Wrap the given absolute path in `AbsPathBuf`
@@ -135,6 +135,24 @@ impl AbsPathBuf {
pub fn pop(&mut self) -> bool {
self.0.pop()
}
+
+ /// Equivalent of [`PathBuf::push`] for `AbsPathBuf`.
+ ///
+ /// Extends `self` with `path`.
+ ///
+ /// If `path` is absolute, it replaces the current path.
+ ///
+ /// On Windows:
+ ///
+ /// * if `path` has a root but no prefix (e.g., `\windows`), it
+ /// replaces everything except for the prefix (if any) of `self`.
+ /// * if `path` has a prefix but no root, it replaces `self`.
+ /// * if `self` has a verbatim prefix (e.g. `\\?\C:\windows`)
+ /// and `path` is not empty, the new path is normalized: all references
+ /// to `.` and `..` are removed.
+ pub fn push<P: AsRef<Utf8Path>>(&mut self, suffix: P) {
+ self.0.push(suffix)
+ }
}
impl fmt::Display for AbsPathBuf {
@@ -197,7 +215,7 @@ impl AbsPath {
///
/// Panics if `path` is not absolute.
pub fn assert(path: &Utf8Path) -> &AbsPath {
- assert!(path.is_absolute());
+ assert!(path.is_absolute(), "{path} is not absolute");
unsafe { &*(path as *const Utf8Path as *const AbsPath) }
}