1
Fork 0

Rollup merge of #92709 - joshtriplett:file-options-docs, r=Mark-Simulacrum

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.
This commit is contained in:
Matthias Krüger 2022-01-12 07:12:12 +01:00 committed by GitHub
commit 5d904c17f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -356,9 +356,10 @@ impl File {
/// open or create a file with specific options if `open()` or `create()` /// open or create a file with specific options if `open()` or `create()`
/// are not appropriate. /// are not appropriate.
/// ///
/// It is equivalent to `OpenOptions::new()` but allows you to write more /// It is equivalent to `OpenOptions::new()`, but allows you to write more
/// readable code. Instead of `OpenOptions::new().read(true).open("foo.txt")` /// readable code. Instead of
/// you can write `File::options().read(true).open("foo.txt")`. This /// `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`. /// also avoids the need to import `OpenOptions`.
/// ///
/// See the [`OpenOptions::new`] function for more details. /// See the [`OpenOptions::new`] function for more details.
@ -369,7 +370,7 @@ impl File {
/// use std::fs::File; /// use std::fs::File;
/// ///
/// fn main() -> std::io::Result<()> { /// 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(()) /// Ok(())
/// } /// }
/// ``` /// ```