Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/libstd/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,24 @@ impl Path {
pub fn is_dir(&self) -> bool {
fs::metadata(self).map(|m| m.is_dir()).unwrap_or(false)
}

/// Returns true if the path is empty.
///
/// # Examples
///
/// ```
/// use std::path::Path;
///
/// let mut path = Path::new("");
/// assert!(path.is_empty());
///
/// path.push("/tmp/foo.rs");
/// assert!(!path.is_empty());
/// ```
#[unstable(feature = "path_is_empty", reason = "recently added", issue = "30259")]
pub fn is_empty(&self) -> bool {
self.inner.is_empty()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -3332,6 +3350,17 @@ mod tests {
}
}

#[test]
pub fn is_empty() {
let path = Path::new("/tmp/foo.rs");
assert!(!path.is_empty());

let mut path_buf = PathBuf::new();
assert!(path_buf.is_empty());
path_buf.push("foo");
assert!(!path_buf.is_empty());
}

#[test]
pub fn test_set_extension() {
macro_rules! tfe(
Expand Down