Skip to content

Add more methods to AbsPath #20478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion crates/paths/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down
Loading