@@ -5,8 +5,8 @@ already existed, the old content is destroyed. Otherwise, a new file is
55created.
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
1010tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
1111quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
1212consequat. 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
1717use std::error::Error;
18- use std::io::prelude::*;
1918use std::fs::File;
19+ use std::io::prelude::*;
2020use std::path::Path;
2121
2222fn 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
6156failure 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