Auto merge of #26642 - remram44:doc-openoptions-missing-write, r=alexcrichton

Setting append without write doesn't give you a writeable file. Showing it as an example in the docs is confusing at best ([reddit](https://www.reddit.com/r/rust/comments/3bbz8w/why_is_writing_a_file_not_working_for_me/))

Using truncate (O_TRUNC) on a read-only file is an error on POSIX systems ("unspecified"). Note however that using create (O_CREAT) with read-only flags is fine.

Related: #26103 (which IMHO is wrong; saying "append is different than write" when should simply be "append needs write". My vote is to make append imply write)
This commit is contained in:
bors 2015-06-28 21:37:07 +00:00
commit 2671e8cee0
1 changed files with 2 additions and 2 deletions

View File

@ -419,7 +419,7 @@ impl OpenOptions {
/// ```no_run
/// use std::fs::OpenOptions;
///
/// let file = OpenOptions::new().append(true).open("foo.txt");
/// let file = OpenOptions::new().write(true).append(true).open("foo.txt");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn append(&mut self, append: bool) -> &mut OpenOptions {
@ -436,7 +436,7 @@ impl OpenOptions {
/// ```no_run
/// use std::fs::OpenOptions;
///
/// let file = OpenOptions::new().truncate(true).open("foo.txt");
/// let file = OpenOptions::new().write(true).truncate(true).open("foo.txt");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn truncate(&mut self, truncate: bool) -> &mut OpenOptions {