@@ -846,6 +846,26 @@ impl DirEntry {
846
846
/// On Windows this function is cheap to call (no extra system calls
847
847
/// needed), but on Unix platforms this function is the equivalent of
848
848
/// calling `symlink_metadata` on the path.
849
+ ///
850
+ /// # Examples
851
+ ///
852
+ /// ```
853
+ /// use std::fs;
854
+ ///
855
+ /// if let Ok(entries) = fs::read_dir(".") {
856
+ /// for entry in entries {
857
+ /// if let Ok(entry) = entry {
858
+ /// // Here, `entry` is a `DirEntry`.
859
+ /// if let Ok(metadata) = entry.metadata() {
860
+ /// // Now let's show our entry's permissions!
861
+ /// println!("{:?}: {:?}", entry.path(), metadata.permissions());
862
+ /// } else {
863
+ /// println!("Couldn't get metadata for {:?}", entry.path());
864
+ /// }
865
+ /// }
866
+ /// }
867
+ /// }
868
+ /// ```
849
869
#[ stable( feature = "dir_entry_ext" , since = "1.1.0" ) ]
850
870
pub fn metadata ( & self ) -> io:: Result < Metadata > {
851
871
self . 0 . metadata ( ) . map ( Metadata )
@@ -861,13 +881,48 @@ impl DirEntry {
861
881
/// On Windows and most Unix platforms this function is free (no extra
862
882
/// system calls needed), but some Unix platforms may require the equivalent
863
883
/// call to `symlink_metadata` to learn about the target file type.
884
+ ///
885
+ /// # Examples
886
+ ///
887
+ /// ```
888
+ /// use std::fs;
889
+ ///
890
+ /// if let Ok(entries) = fs::read_dir(".") {
891
+ /// for entry in entries {
892
+ /// if let Ok(entry) = entry {
893
+ /// // Here, `entry` is a `DirEntry`.
894
+ /// if let Ok(file_type) = entry.file_type() {
895
+ /// // Now let's show our entry's file type!
896
+ /// println!("{:?}: {:?}", entry.path(), file_type);
897
+ /// } else {
898
+ /// println!("Couldn't get file type for {:?}", entry.path());
899
+ /// }
900
+ /// }
901
+ /// }
902
+ /// }
903
+ /// ```
864
904
#[ stable( feature = "dir_entry_ext" , since = "1.1.0" ) ]
865
905
pub fn file_type ( & self ) -> io:: Result < FileType > {
866
906
self . 0 . file_type ( ) . map ( FileType )
867
907
}
868
908
869
909
/// Returns the bare file name of this directory entry without any other
870
910
/// leading path component.
911
+ ///
912
+ /// # Examples
913
+ ///
914
+ /// ```
915
+ /// use std::fs;
916
+ ///
917
+ /// if let Ok(entries) = fs::read_dir(".") {
918
+ /// for entry in entries {
919
+ /// if let Ok(entry) = entry {
920
+ /// // Here, `entry` is a `DirEntry`.
921
+ /// println!("{:?}", entry.file_name());
922
+ /// }
923
+ /// }
924
+ /// }
925
+ /// ```
871
926
#[ stable( feature = "dir_entry_ext" , since = "1.1.0" ) ]
872
927
pub fn file_name ( & self ) -> OsString {
873
928
self . 0 . file_name ( )
0 commit comments