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).
This commit is contained in:
parent
c1b8bd2d6f
commit
78ec055a14
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user