@@ -5,8 +5,8 @@ already existed, the old content is destroyed. Otherwise, a new file is
5
5
created.
6
6
7
7
``` 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
10
10
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
11
11
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
12
12
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.
15
15
";
16
16
17
17
use std::error::Error;
18
- use std::io::prelude::*;
19
18
use std::fs::File;
19
+ use std::io::prelude::*;
20
20
use std::path::Path;
21
21
22
22
fn main() {
@@ -25,18 +25,13 @@ fn main() {
25
25
26
26
// Open a file in write-only mode, returns `io::Result<File>`
27
27
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()),
31
29
Ok(file) => file,
32
30
};
33
31
34
32
// Write the `LOREM_IPSUM` string to `file`, returns `io::Result<()>`
35
33
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()),
40
35
Ok(_) => println!("successfully wrote to {}", display),
41
36
}
42
37
}
@@ -60,5 +55,6 @@ proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
60
55
(As in the previous example, you are encouraged to test this example under
61
56
failure conditions.)
62
57
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