Skip to content

Commit 7e66d6c

Browse files
committed
Implement Path::is_empty
1 parent d85276b commit 7e66d6c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

library/std/src/path.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,6 +2756,28 @@ impl Path {
27562756
iter_after(self.components().rev(), child.components().rev()).is_some()
27572757
}
27582758

2759+
/// Checks whether the `Path` is empty.
2760+
///
2761+
/// # Examples
2762+
///
2763+
/// ```
2764+
/// #![feature(path_is_empty)]
2765+
/// use std::path::Path;
2766+
///
2767+
/// let path = Path::new("");
2768+
/// assert!(path.is_empty());
2769+
///
2770+
/// let path = Path::new("foo");
2771+
/// assert!(!path.is_empty());
2772+
///
2773+
/// let path = Path::new(".");
2774+
/// assert!(!path.is_empty());
2775+
/// ```
2776+
#[unstable(feature = "path_is_empty", issue = "148494")]
2777+
pub fn is_empty(&self) -> bool {
2778+
self.as_os_str().is_empty()
2779+
}
2780+
27592781
/// Extracts the stem (non-extension) portion of [`self.file_name`].
27602782
///
27612783
/// [`self.file_name`]: Path::file_name

0 commit comments

Comments
 (0)