Skip to content

Commit 78ec055

Browse files
committed
Add .write(true) to append and truncate examples
Setting append without write doesn't give you a writeable file. Showing it as an example in the docs is confusing at best. Using truncate on a read-only file is an error on POSIX systems (note however that using create with read-only flags is fine).
1 parent c1b8bd2 commit 78ec055

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/libstd/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl OpenOptions {
419419
/// ```no_run
420420
/// use std::fs::OpenOptions;
421421
///
422-
/// let file = OpenOptions::new().append(true).open("foo.txt");
422+
/// let file = OpenOptions::new().write(true).append(true).open("foo.txt");
423423
/// ```
424424
#[stable(feature = "rust1", since = "1.0.0")]
425425
pub fn append(&mut self, append: bool) -> &mut OpenOptions {
@@ -436,7 +436,7 @@ impl OpenOptions {
436436
/// ```no_run
437437
/// use std::fs::OpenOptions;
438438
///
439-
/// let file = OpenOptions::new().truncate(true).open("foo.txt");
439+
/// let file = OpenOptions::new().write(true).truncate(true).open("foo.txt");
440440
/// ```
441441
#[stable(feature = "rust1", since = "1.0.0")]
442442
pub fn truncate(&mut self, truncate: bool) -> &mut OpenOptions {

0 commit comments

Comments
 (0)