about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2022-01-09 14:08:08 -0800
committerMark Rousskov <mark.simulacrum@gmail.com>2022-01-10 17:35:17 -0500
commitc91ad5d0f251eb412e4db89fd929117ee970ea89 (patch)
tree30f2ae75fd46cfe10cec076144f0d527ca916478
parent89b9f7b284aacc5f8613438b80e4dd7bdd10549e (diff)
downloadrust-c91ad5d0f251eb412e4db89fd929117ee970ea89.tar.gz
rust-c91ad5d0f251eb412e4db89fd929117ee970ea89.zip
Improve documentation for File::options to give a more likely example
`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.
-rw-r--r--library/std/src/fs.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs
index dae85027b6c..a00b5e12323 100644
--- a/library/std/src/fs.rs
+++ b/library/std/src/fs.rs
@@ -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.
@@ -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(())
     /// }
     /// ```