Skip to content

Commit

Permalink
Improve documentation for File::options to give a more likely example
Browse files Browse the repository at this point in the history
`File::options().read(true).open(...)` is equivalent to just
`File::open`. Change the example to set the `append` flag instead, and
then change the filename to something more likely to be written in
append mode.
  • Loading branch information
joshtriplett authored and Mark-Simulacrum committed Jan 10, 2022
1 parent 89b9f7b commit c91ad5d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,10 @@ impl File {
/// open or create a file with specific options if `open()` or `create()`
/// are not appropriate.
///
/// It is equivalent to `OpenOptions::new()` but allows you to write more
/// readable code. Instead of `OpenOptions::new().read(true).open("foo.txt")`
/// you can write `File::options().read(true).open("foo.txt")`. This
/// It is equivalent to `OpenOptions::new()`, but allows you to write more
/// readable code. Instead of
/// `OpenOptions::new().append(true).open("example.log")`,
/// you can write `File::options().append(true).open("example.log")`. This
/// also avoids the need to import `OpenOptions`.
///
/// See the [`OpenOptions::new`] function for more details.
Expand All @@ -369,7 +370,7 @@ impl File {
/// use std::fs::File;
///
/// fn main() -> std::io::Result<()> {
/// let mut f = File::options().read(true).open("foo.txt")?;
/// let mut f = File::options().append(true).open("example.log")?;
/// Ok(())
/// }
/// ```
Expand Down

0 comments on commit c91ad5d

Please sign in to comment.