From 3a9597cd32a4e95b3a4cd2aa06bc241cc2f29e96 Mon Sep 17 00:00:00 2001 From: Wouter Geraedts Date: Sun, 13 Oct 2019 19:07:12 +0200 Subject: [PATCH] Implemented Path::has_root --- src/path/path.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/path/path.rs b/src/path/path.rs index 2c0f718e..be34172d 100644 --- a/src/path/path.rs +++ b/src/path/path.rs @@ -250,6 +250,26 @@ impl Path { self.inner.file_stem() } + /// Returns `true` if the `Path` has a root. + /// + /// * On Unix, a path has a root if it begins with `/`. + /// + /// * On Windows, a path has a root if it: + /// * has no prefix and begins with a separator, e.g., `\windows` + /// * has a prefix followed by a separator, e.g., `c:\windows` but not `c:windows` + /// * has any non-disk prefix, e.g., `\\server\share` + /// + /// # Examples + /// + /// ``` + /// use async_std::path::Path; + /// + /// assert!(Path::new("/etc/passwd").has_root()); + /// ``` + pub fn has_root(&self) -> bool { + self.inner.has_root() + } + /// Converts a [`Box`][`Box`] into a [`PathBuf`] without copying or /// allocating. ///