File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -277,6 +277,12 @@ impl OsStr {
277
277
self . to_bytes ( ) . and_then ( |b| CString :: new ( b) . ok ( ) )
278
278
}
279
279
280
+ /// Checks if the string is empty.
281
+ #[ unstable( feature = "osstr_is_empty" , reason = "recently added" , issue = "30259" ) ]
282
+ pub fn is_empty ( & self ) -> bool {
283
+ self . inner . inner . is_empty ( )
284
+ }
285
+
280
286
/// Gets the underlying byte representation.
281
287
///
282
288
/// Note: it is *crucial* that this API is private, to avoid
Original file line number Diff line number Diff line change @@ -1897,6 +1897,24 @@ impl Path {
1897
1897
pub fn is_dir ( & self ) -> bool {
1898
1898
fs:: metadata ( self ) . map ( |m| m. is_dir ( ) ) . unwrap_or ( false )
1899
1899
}
1900
+
1901
+ /// Checks if the path buffer is empty. On Windows, it will return false if the inner string is
1902
+ /// invalid unicode. On Unix, this is a no-op.
1903
+ ///
1904
+ /// # Examples
1905
+ ///
1906
+ /// ```
1907
+ /// # #![feature(os_extras)]
1908
+ /// use std::path::Path;
1909
+ ///
1910
+ /// let path = Path::new("/tmp/foo.rs");
1911
+ ///
1912
+ /// assert!(!path.is_empty());
1913
+ /// ```
1914
+ #[ unstable( feature = "path_is_empty" , reason = "recently added" , issue = "30259" ) ]
1915
+ pub fn is_empty ( & self ) -> bool {
1916
+ self . inner . is_empty ( )
1917
+ }
1900
1918
}
1901
1919
1902
1920
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -3239,6 +3257,17 @@ mod tests {
3239
3257
}
3240
3258
}
3241
3259
3260
+ #[ test]
3261
+ pub fn is_empty ( ) {
3262
+ let path = Path :: new ( "/tmp/foo.rs" ) ;
3263
+ let mut path_buf = PathBuf :: new ( ) ;
3264
+
3265
+ assert ! ( !path. is_empty( ) ) ;
3266
+ assert ! ( path_buf. is_empty( ) ) ;
3267
+ path_buf. push ( "catsarecute" ) ;
3268
+ assert ! ( !path_buf. is_empty( ) ) ;
3269
+ }
3270
+
3242
3271
#[ test]
3243
3272
pub fn test_set_extension ( ) {
3244
3273
macro_rules! tfe(
You can’t perform that action at this time.
0 commit comments