diff --git a/src/path/path.rs b/src/path/path.rs index e159ca1b..f4cae23b 100644 --- a/src/path/path.rs +++ b/src/path/path.rs @@ -566,6 +566,31 @@ impl Path { fs::read_link(self).await } + /// Determines whether `base` is a prefix of `self`. + /// + /// Only considers whole path components to match. + /// + /// # Examples + /// + /// ``` + /// use async_std::path::Path; + /// + /// let path = Path::new("/etc/passwd"); + /// + /// assert!(path.starts_with("/etc")); + /// assert!(path.starts_with("/etc/")); + /// assert!(path.starts_with("/etc/passwd")); + /// assert!(path.starts_with("/etc/passwd/")); + /// + /// assert!(!path.starts_with("/e")); + /// ``` + pub fn starts_with>(&self, base: P) -> bool + where + P: std::convert::AsRef, + { + self.inner.starts_with(base) + } + /// Queries the metadata about a file without following symlinks. /// /// This is an alias to [`fs::symlink_metadata`].