From 4c4f4615d8f3df36ea3e010ddb46d7cc59c4a457 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 15 Sep 2020 14:39:10 +0000 Subject: [PATCH 1/2] Improve documentation of File::with_options --- library/std/src/fs.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 161bfe3795c2c..2c37746fa5b0d 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -358,18 +358,12 @@ impl File { OpenOptions::new().write(true).create(true).truncate(true).open(path.as_ref()) } - /// Returns a new OpenOptions object. + /// Returns a builder struct to configure how a file is opened. /// - /// This function returns a new OpenOptions object that you can use to - /// open or create a file with specific options if `open()` or `create()` - /// are not appropriate. + /// This function returns an empty [`OpenOptions`] object + /// to avoid the need of importing [`OpenOptions`]. /// - /// 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::with_options().read(true).open("foo.txt")`. This - /// also avoids the need to import `OpenOptions`. - /// - /// See the [`OpenOptions::new`] function for more details. + /// See [`OpenOptions::new`] function for more details. /// /// # Examples /// @@ -378,7 +372,7 @@ impl File { /// use std::fs::File; /// /// fn main() -> std::io::Result<()> { - /// let mut f = File::with_options().read(true).open("foo.txt")?; + /// let _ = File::with_options().read(true).open("foo.txt")?; /// Ok(()) /// } /// ``` From 27dcb3cfbacf217f96c611b55525c8280c8351cc Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 15 Sep 2020 14:45:15 +0000 Subject: [PATCH 2/2] Rename File::with_options to builder --- library/std/src/fs.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 2c37746fa5b0d..e83a61ace03c0 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -368,16 +368,16 @@ impl File { /// # Examples /// /// ```no_run - /// #![feature(with_options)] + /// #![feature(file_builder)] /// use std::fs::File; /// /// fn main() -> std::io::Result<()> { - /// let _ = File::with_options().read(true).open("foo.txt")?; + /// let _ = File::builder().read(true).open("foo.txt")?; /// Ok(()) /// } /// ``` - #[unstable(feature = "with_options", issue = "65439")] - pub fn with_options() -> OpenOptions { + #[unstable(feature = "file_builder", issue = "65439")] + pub fn builder() -> OpenOptions { OpenOptions::new() }