Skip to content

Commit 3a9597c

Browse files
committed
Implemented Path::has_root
1 parent 28e936f commit 3a9597c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/path/path.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,26 @@ impl Path {
250250
self.inner.file_stem()
251251
}
252252

253+
/// Returns `true` if the `Path` has a root.
254+
///
255+
/// * On Unix, a path has a root if it begins with `/`.
256+
///
257+
/// * On Windows, a path has a root if it:
258+
/// * has no prefix and begins with a separator, e.g., `\windows`
259+
/// * has a prefix followed by a separator, e.g., `c:\windows` but not `c:windows`
260+
/// * has any non-disk prefix, e.g., `\\server\share`
261+
///
262+
/// # Examples
263+
///
264+
/// ```
265+
/// use async_std::path::Path;
266+
///
267+
/// assert!(Path::new("/etc/passwd").has_root());
268+
/// ```
269+
pub fn has_root(&self) -> bool {
270+
self.inner.has_root()
271+
}
272+
253273
/// Converts a [`Box<Path>`][`Box`] into a [`PathBuf`] without copying or
254274
/// allocating.
255275
///

0 commit comments

Comments
 (0)