mirror of
https://github.com/async-rs/async-std.git
synced 2025-01-16 10:49:55 +00:00
Implemented Path::starts_with
This commit is contained in:
parent
d349333a43
commit
942403c52c
1 changed files with 25 additions and 0 deletions
|
@ -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<P: AsRef<Path>>(&self, base: P) -> bool
|
||||
where
|
||||
P: std::convert::AsRef<std::path::Path>,
|
||||
{
|
||||
self.inner.starts_with(base)
|
||||
}
|
||||
|
||||
/// Queries the metadata about a file without following symlinks.
|
||||
///
|
||||
/// This is an alias to [`fs::symlink_metadata`].
|
||||
|
|
Loading…
Reference in a new issue