Skip to content

Commit 20f58ea

Browse files
committed
Implemented Path::is_absolute
1 parent 3a9597c commit 20f58ea

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/path/path.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,28 @@ impl Path {
281281
inner.into_path_buf().into()
282282
}
283283

284+
/// Returns `true` if the `Path` is absolute, i.e., if it is independent of
285+
/// the current directory.
286+
///
287+
/// * On Unix, a path is absolute if it starts with the root, so
288+
/// `is_absolute` and [`has_root`] are equivalent.
289+
///
290+
/// * On Windows, a path is absolute if it has a prefix and starts with the
291+
/// root: `c:\windows` is absolute, while `c:temp` and `\temp` are not.
292+
///
293+
/// # Examples
294+
///
295+
/// ```
296+
/// use async_std::path::Path;
297+
///
298+
/// assert!(!Path::new("foo.txt").is_absolute());
299+
/// ```
300+
///
301+
/// [`has_root`]: #method.has_root
302+
pub fn is_absolute(&self) -> bool {
303+
self.inner.is_absolute()
304+
}
305+
284306
/// Queries the file system to get information about a file, directory, etc.
285307
///
286308
/// This function will traverse symbolic links to query information about the

0 commit comments

Comments
 (0)