mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 18:43:38 +00:00
Rollup merge of #25068 - bguiz:patch-3, r=steveklabnik
- `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:
commit
b8fedad89b
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user