=BG= minor: File::open --> File::create in rust book

- `FIle::open` is for opening a file in read-only mode
- `FIle::create` is for opening a file in write-only mode, which is what we want instead for this example to make sense
This commit is contained in:
Brendan Graetz 2015-05-03 20:42:47 +10:00
parent 0d7d3ec9d2
commit 75a3e29042

View File

@ -252,7 +252,7 @@ struct Info {
}
fn write_info(info: &Info) -> io::Result<()> {
let mut file = File::open("my_best_friends.txt").unwrap();
let mut file = File::create("my_best_friends.txt").unwrap();
if let Err(e) = writeln!(&mut file, "name: {}", info.name) {
return Err(e)
@ -282,7 +282,7 @@ struct Info {
}
fn write_info(info: &Info) -> io::Result<()> {
let mut file = try!(File::open("my_best_friends.txt"));
let mut file = try!(File::create("my_best_friends.txt"));
try!(writeln!(&mut file, "name: {}", info.name));
try!(writeln!(&mut file, "age: {}", info.age));