Skip to content

Commit 746e0c6

Browse files
authored
Merge pull request #1164 from lzutao/openoptions
Fix #1147 - No more `open_mode` method
2 parents d08e68d + 075dbca commit 746e0c6

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/std_misc/file/create.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ already existed, the old content is destroyed. Otherwise, a new file is
55
created.
66

77
```rust,ignore
8-
static LOREM_IPSUM: &'static str =
9-
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
8+
static LOREM_IPSUM: &str =
9+
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
1010
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
1111
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
1212
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
@@ -15,8 +15,8 @@ proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
1515
";
1616
1717
use std::error::Error;
18-
use std::io::prelude::*;
1918
use std::fs::File;
19+
use std::io::prelude::*;
2020
use std::path::Path;
2121
2222
fn main() {
@@ -25,18 +25,13 @@ fn main() {
2525
2626
// Open a file in write-only mode, returns `io::Result<File>`
2727
let mut file = match File::create(&path) {
28-
Err(why) => panic!("couldn't create {}: {}",
29-
display,
30-
why.description()),
28+
Err(why) => panic!("couldn't create {}: {}", display, why.description()),
3129
Ok(file) => file,
3230
};
3331
3432
// Write the `LOREM_IPSUM` string to `file`, returns `io::Result<()>`
3533
match file.write_all(LOREM_IPSUM.as_bytes()) {
36-
Err(why) => {
37-
panic!("couldn't write to {}: {}", display,
38-
why.description())
39-
},
34+
Err(why) => panic!("couldn't write to {}: {}", display, why.description()),
4035
Ok(_) => println!("successfully wrote to {}", display),
4136
}
4237
}
@@ -60,5 +55,6 @@ proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
6055
(As in the previous example, you are encouraged to test this example under
6156
failure conditions.)
6257

63-
There is also a more generic `open_mode` method that can open files in other
64-
modes like: read+write, append, etc.
58+
There is [`OpenOptions`] struct that can be used to configure how a file is opened.
59+
60+
[`OpenOptions`]: https://doc.rust-lang.org/std/fs/struct.OpenOptions.html

0 commit comments

Comments
 (0)