From 95a36df0e11ac4930a58e6fbb7acd2f8d18f3e35 Mon Sep 17 00:00:00 2001 From: BenjaminBrienen Date: Sun, 17 Aug 2025 14:13:24 +0200 Subject: [PATCH] add more methods to AbsPath --- crates/paths/src/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/paths/src/lib.rs b/crates/paths/src/lib.rs index 2c6a82bf0c3f..f77e8b1b416d 100644 --- a/crates/paths/src/lib.rs +++ b/crates/paths/src/lib.rs @@ -201,6 +201,16 @@ impl<'a> TryFrom<&'a Utf8Path> for &'a AbsPath { } impl AbsPath { + /// Creates a new [`AbsPath`] from `path`, assuming that it is absolute. + pub fn new_unchecked(path: &Utf8Path) -> &AbsPath { + // SAFETY: This is safe because `path` is a valid reference. + unsafe { &*(path as *const Utf8Path as *const AbsPath) } + } + + pub fn as_utf8_path(&self) -> &Utf8Path { + self.as_ref() + } + /// Wrap the given absolute path in `AbsPath` /// /// # Panics @@ -242,7 +252,7 @@ impl AbsPath { AbsPathBuf(normalize_path(&self.0)) } - /// Equivalent of [`Utf8Path::to_path_buf`] for `AbsPath`. + /// Converts an [`AbsPath`] to an owned [`AbsPathBuf`]. pub fn to_path_buf(&self) -> AbsPathBuf { AbsPathBuf::try_from(self.0.to_path_buf()).unwrap() }