Skip to content

Commit b5f3ca1

Browse files
authored
Rollup merge of rust-lang#153272 - wmmc88:add-path-absolute-method, r=tgross35
Add `Path::absolute` method as alias for `std::path::absolute` `Path::canonicalize()` is an alias for `fs::canonicalize()`, but there's no equivalent `Path::absolute()` for `path::absolute()`. This adds one. Discussed in rust-lang#92750 (comment), Chris [said](rust-lang#92750 (comment)) a PR would be welcome. Tracking issue: rust-lang#153328
2 parents 010bca6 + bde5b58 commit b5f3ca1

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)