Skip to content

Commit 64aea50

Browse files
committed
Add is_empty() for PathBuf, fix #30259
1 parent a503c80 commit 64aea50

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/libstd/path.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,16 @@ impl PathBuf {
11461146
pub fn into_os_string(self) -> OsString {
11471147
self.inner
11481148
}
1149+
1150+
/// Checks if the path buffer is empty. On Windows, it will return false if the inner string is
1151+
/// invalid unicode. On Unix, this is a no-op.
1152+
pub fn is_empty(&self) -> bool {
1153+
if let Some(b) = self.inner.to_bytes() {
1154+
b.is_empty()
1155+
} else {
1156+
true
1157+
}
1158+
}
11491159
}
11501160

11511161
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)