@@ -58,28 +58,37 @@ pub struct File {
58
58
59
59
/// Metadata information about a file.
60
60
///
61
- /// This structure is returned from the `metadata` function or method and
61
+ /// This structure is returned from the [ `metadata`] function or method and
62
62
/// represents known metadata about a file such as its permissions, size,
63
63
/// modification times, etc.
64
+ ///
65
+ /// [`metadata`]: fn.metadata.html
64
66
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
65
67
#[ derive( Clone ) ]
66
68
pub struct Metadata ( fs_imp:: FileAttr ) ;
67
69
68
70
/// Iterator over the entries in a directory.
69
71
///
70
- /// This iterator is returned from the `read_dir` function of this module and
71
- /// will yield instances of `io::Result<DirEntry>`. Through a `DirEntry`
72
+ /// This iterator is returned from the [ `read_dir`] function of this module and
73
+ /// will yield instances of `io::Result<DirEntry>`. Through a [ `DirEntry`]
72
74
/// information like the entry's path and possibly other metadata can be
73
75
/// learned.
74
76
///
77
+ /// [`read_dir`]: fn.read_dir.html
78
+ /// [`DirEntry`]: struct.DirEntry.html
79
+ ///
75
80
/// # Errors
76
81
///
77
- /// This `io::Result` will be an `Err` if there's some sort of intermittent
82
+ /// This [ `io::Result`] will be an `Err` if there's some sort of intermittent
78
83
/// IO error during iteration.
84
+ ///
85
+ /// [`io::Result`]: ../io/type.Result.html
79
86
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
80
87
pub struct ReadDir ( fs_imp:: ReadDir ) ;
81
88
82
- /// Entries returned by the `ReadDir` iterator.
89
+ /// Entries returned by the [`ReadDir`] iterator.
90
+ ///
91
+ /// [`ReadDir`]: struct.ReadDir.html
83
92
///
84
93
/// An instance of `DirEntry` represents an entry inside of a directory on the
85
94
/// filesystem. Each entry can be inspected via methods to learn about the full
@@ -89,17 +98,23 @@ pub struct DirEntry(fs_imp::DirEntry);
89
98
90
99
/// Options and flags which can be used to configure how a file is opened.
91
100
///
92
- /// This builder exposes the ability to configure how a `File` is opened and
93
- /// what operations are permitted on the open file. The `File::open` and
94
- /// `File::create` methods are aliases for commonly used options using this
101
+ /// This builder exposes the ability to configure how a [ `File`] is opened and
102
+ /// what operations are permitted on the open file. The [ `File::open`] and
103
+ /// [ `File::create`] methods are aliases for commonly used options using this
95
104
/// builder.
96
105
///
97
- /// Generally speaking, when using `OpenOptions`, you'll first call `new()`,
98
- /// then chain calls to methods to set each option, then call `open()`, passing
99
- /// the path of the file you're trying to open. This will give you a
106
+ /// [`File`]: struct.File.html
107
+ /// [`File::open`]: struct.File.html#method.open
108
+ /// [`File::create`]: struct.File.html#method.create
109
+ ///
110
+ /// Generally speaking, when using `OpenOptions`, you'll first call [`new()`],
111
+ /// then chain calls to methods to set each option, then call [`open()`],
112
+ /// passing the path of the file you're trying to open. This will give you a
100
113
/// [`io::Result`][result] with a [`File`][file] inside that you can further
101
114
/// operate on.
102
115
///
116
+ /// [`new()`]: struct.OpenOptions.html#method.new
117
+ /// [`open()`]: struct.OpenOptions.html#method.open
103
118
/// [result]: ../io/type.Result.html
104
119
/// [file]: struct.File.html
105
120
///
@@ -131,10 +146,12 @@ pub struct OpenOptions(fs_imp::OpenOptions);
131
146
132
147
/// Representation of the various permissions on a file.
133
148
///
134
- /// This module only currently provides one bit of information, `readonly`,
149
+ /// This module only currently provides one bit of information, [ `readonly`] ,
135
150
/// which is exposed on all currently supported platforms. Unix-specific
136
151
/// functionality, such as mode bits, is available through the
137
152
/// `os::unix::PermissionsExt` trait.
153
+ ///
154
+ /// [`readonly`]: struct.Permissions.html#method.readonly
138
155
#[ derive( Clone , PartialEq , Eq , Debug ) ]
139
156
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
140
157
pub struct Permissions ( fs_imp:: FilePermissions ) ;
@@ -829,6 +846,26 @@ impl DirEntry {
829
846
/// On Windows this function is cheap to call (no extra system calls
830
847
/// needed), but on Unix platforms this function is the equivalent of
831
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
+ /// ```
832
869
#[ stable( feature = "dir_entry_ext" , since = "1.1.0" ) ]
833
870
pub fn metadata ( & self ) -> io:: Result < Metadata > {
834
871
self . 0 . metadata ( ) . map ( Metadata )
@@ -844,13 +881,48 @@ impl DirEntry {
844
881
/// On Windows and most Unix platforms this function is free (no extra
845
882
/// system calls needed), but some Unix platforms may require the equivalent
846
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
+ /// ```
847
904
#[ stable( feature = "dir_entry_ext" , since = "1.1.0" ) ]
848
905
pub fn file_type ( & self ) -> io:: Result < FileType > {
849
906
self . 0 . file_type ( ) . map ( FileType )
850
907
}
851
908
852
909
/// Returns the bare file name of this directory entry without any other
853
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
+ /// ```
854
926
#[ stable( feature = "dir_entry_ext" , since = "1.1.0" ) ]
855
927
pub fn file_name ( & self ) -> OsString {
856
928
self . 0 . file_name ( )
0 commit comments