@@ -9,6 +9,8 @@ use crate::path::Path;
9
9
use crate :: sys;
10
10
use crate :: sys_common:: { AsInner , AsInnerMut , FromInner } ;
11
11
// Used for `File::read` on intra-doc links
12
+ use crate :: ffi:: OsStr ;
13
+ use crate :: sealed:: Sealed ;
12
14
#[ allow( unused_imports) ]
13
15
use io:: { Read , Write } ;
14
16
@@ -839,6 +841,42 @@ impl DirEntryExt for fs::DirEntry {
839
841
}
840
842
}
841
843
844
+ /// Sealed Unix-specific extension methods for [`fs::DirEntry`].
845
+ #[ unstable( feature = "dir_entry_ext2" , issue = "85573" ) ]
846
+ pub trait DirEntryExt2 : Sealed {
847
+ /// Returns a reference to the underlying `OsStr` of this entry's filename.
848
+ ///
849
+ /// # Examples
850
+ ///
851
+ /// ```
852
+ /// use std::os::unix::fs::DirEntryExt2;
853
+ /// use std::{fs, io};
854
+ ///
855
+ /// fn main() -> io::Result<()> {
856
+ /// let mut entries = fs::read_dir(".")?.collect::<Result<Vec<_>, io::Error>>()?;
857
+ /// entries.sort_unstable_by(|a, b| a.file_name_ref().cmp(b.file_name_ref()));
858
+ ///
859
+ /// for p in entries {
860
+ /// println!("{:?}", p);
861
+ /// }
862
+ ///
863
+ /// Ok(())
864
+ /// }
865
+ /// ```
866
+ fn file_name_ref ( & self ) -> & OsStr ;
867
+ }
868
+
869
+ /// Allows extension traits within `std`.
870
+ #[ unstable( feature = "sealed" , issue = "none" ) ]
871
+ impl Sealed for fs:: DirEntry { }
872
+
873
+ #[ unstable( feature = "dir_entry_ext2" , issue = "85573" ) ]
874
+ impl DirEntryExt2 for fs:: DirEntry {
875
+ fn file_name_ref ( & self ) -> & OsStr {
876
+ self . as_inner ( ) . file_name_os_str ( )
877
+ }
878
+ }
879
+
842
880
/// Creates a new symbolic link on the filesystem.
843
881
///
844
882
/// The `link` path will be a symbolic link pointing to the `original` path.
0 commit comments