Skip to content

Commit bde5b58

Browse files
committed
Add Path::absolute method as alias for path::absolute
Add a convenience method Path::absolute() that delegates to the existing free function std::path::absolute(), mirroring the pattern of Path::canonicalize() delegating to fs::canonicalize(). Tracking issue: #153328
1 parent 8038127 commit bde5b58

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

library/std/src/path.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3308,6 +3308,34 @@ impl Path {
33083308
fs::canonicalize(self)
33093309
}
33103310

3311+
/// Makes the path absolute without accessing the filesystem.
3312+
///
3313+
/// This is an alias to [`path::absolute`](absolute).
3314+
///
3315+
/// # Errors
3316+
///
3317+
/// This function may return an error in the following situations:
3318+
///
3319+
/// * If the path is syntactically invalid; in particular, if it is empty.
3320+
/// * If getting the [current directory][crate::env::current_dir] fails.
3321+
///
3322+
/// # Examples
3323+
///
3324+
/// ```no_run
3325+
/// #![feature(path_absolute_method)]
3326+
/// use std::path::Path;
3327+
///
3328+
/// let path = Path::new("foo/./bar");
3329+
/// let absolute = path.absolute()?;
3330+
/// assert!(absolute.is_absolute());
3331+
/// # Ok::<(), std::io::Error>(())
3332+
/// ```
3333+
#[unstable(feature = "path_absolute_method", issue = "153328")]
3334+
#[inline]
3335+
pub fn absolute(&self) -> io::Result<PathBuf> {
3336+
absolute(self)
3337+
}
3338+
33113339
/// Normalize a path, including `..` without traversing the filesystem.
33123340
///
33133341
/// Returns an error if normalization would leave leading `..` components.

0 commit comments

Comments
 (0)