Skip to content

Commit dafbe97

Browse files
authored
Rollup merge of #35010 - GuillaumeGomez:file_doc, r=steveklabnik
Improve Open doc Part of #29356. r? @steveklabnik
2 parents 181d39d + debb2ac commit dafbe97

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/libstd/fs.rs

+23-5
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,14 @@ pub struct DirBuilder {
173173
impl File {
174174
/// Attempts to open a file in read-only mode.
175175
///
176-
/// See the `OpenOptions::open` method for more details.
176+
/// See the [`OpenOptions::open`] method for more details.
177177
///
178178
/// # Errors
179179
///
180180
/// This function will return an error if `path` does not already exist.
181-
/// Other errors may also be returned according to `OpenOptions::open`.
181+
/// Other errors may also be returned according to [`OpenOptions::open`].
182+
///
183+
/// [`OpenOptions::open`]: struct.OpenOptions.html#method.open
182184
///
183185
/// # Examples
184186
///
@@ -200,7 +202,9 @@ impl File {
200202
/// This function will create a file if it does not exist,
201203
/// and will truncate it if it does.
202204
///
203-
/// See the `OpenOptions::open` function for more details.
205+
/// See the [`OpenOptions::open`] function for more details.
206+
///
207+
/// [`OpenOptions::open`]: struct.OpenOptions.html#method.open
204208
///
205209
/// # Examples
206210
///
@@ -241,15 +245,17 @@ impl File {
241245
self.inner.fsync()
242246
}
243247

244-
/// This function is similar to `sync_all`, except that it may not
248+
/// This function is similar to [`sync_all`], except that it may not
245249
/// synchronize file metadata to the filesystem.
246250
///
247251
/// This is intended for use cases that must synchronize content, but don't
248252
/// need the metadata on disk. The goal of this method is to reduce disk
249253
/// operations.
250254
///
251255
/// Note that some platforms may simply implement this in terms of
252-
/// `sync_all`.
256+
/// [`sync_all`].
257+
///
258+
/// [`sync_all`]: struct.File.html#method.sync_all
253259
///
254260
/// # Examples
255261
///
@@ -321,6 +327,18 @@ impl File {
321327
/// The returned `File` is a reference to the same state that this object
322328
/// references. Both handles will read and write with the same cursor
323329
/// position.
330+
///
331+
/// # Examples
332+
///
333+
/// ```no_run
334+
/// use std::fs::File;
335+
///
336+
/// # fn foo() -> std::io::Result<()> {
337+
/// let mut f = try!(File::open("foo.txt"));
338+
/// let file_copy = try!(f.try_clone());
339+
/// # Ok(())
340+
/// # }
341+
/// ```
324342
#[stable(feature = "file_try_clone", since = "1.9.0")]
325343
pub fn try_clone(&self) -> io::Result<File> {
326344
Ok(File {

0 commit comments

Comments
 (0)