Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openoptions docs #44541

Merged
merged 2 commits into from
Sep 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,14 +560,26 @@ impl OpenOptions {
///
/// One maybe obvious note when using append-mode: make sure that all data
/// that belongs together is written to the file in one operation. This
/// can be done by concatenating strings before passing them to `write()`,
/// can be done by concatenating strings before passing them to [`write()`],
/// or using a buffered writer (with a buffer of adequate size),
/// and calling `flush()` when the message is complete.
/// and calling [`flush()`] when the message is complete.
///
/// If a file is opened with both read and append access, beware that after
/// opening, and after every write, the position for reading may be set at the
/// end of the file. So, before writing, save the current position (using
/// `seek(SeekFrom::Current(0))`, and restore it before the next read.
/// [`seek`]`(`[`SeekFrom`]`::`[`Current`]`(0))`, and restore it before the next read.
///
/// ## Note
///
/// This function doesn't create the file if it doesn't exist. Use the [`create`]
/// method to do so.
///
/// [`write()`]: ../../std/fs/struct.File.html#method.write
/// [`flush()`]: ../../std/fs/struct.File.html#method.flush
/// [`seek`]: ../../std/fs/struct.File.html#method.seek
/// [`SeekFrom`]: ../../std/io/enum.SeekFrom.html
/// [`Current`]: ../../std/io/enum.SeekFrom.html#variant.Current
/// [`create`]: #method.create
///
/// # Examples
///
Expand Down Expand Up @@ -605,9 +617,12 @@ impl OpenOptions {
/// This option indicates whether a new file will be created if the file
/// does not yet already exist.
///
/// In order for the file to be created, `write` or `append` access must
/// In order for the file to be created, [`write`] or [`append`] access must
/// be used.
///
/// [`write`]: #method.write
/// [`append`]: #method.append
///
/// # Examples
///
/// ```no_run
Expand All @@ -630,12 +645,15 @@ impl OpenOptions {
/// whether a file exists and creating a new one, the file may have been
/// created by another process (a TOCTOU race condition / attack).
///
/// If `.create_new(true)` is set, `.create()` and `.truncate()` are
/// If `.create_new(true)` is set, [`.create()`] and [`.truncate()`] are
/// ignored.
///
/// The file must be opened with write or append access in order to create
/// a new file.
///
/// [`.create()`]: #method.create
/// [`.truncate()`]: #method.truncate
///
/// # Examples
///
/// ```no_run
Expand Down