1 Please insert this text after the paragraph ending in “ergonomic way to write
6 Speaking of different ways to write this function, Listing 9-9 shows that
7 there’s a way to make this even shorter.
15 fn read_username_from_file() -> Result<String, io::Error> {
16 fs::read_to_string("hello.txt")
20 Listing 9-9: Using `fs::read_to_string` instead of opening and then reading the
23 Reading a file into a string is a fairly common operation, so Rust provides the
24 convenient `fs::read_to_string` function that opens the file, creates a new
25 `String`, reads the contents of the file, puts the contents into that `String`,
26 and returns it. Of course, using `fs::read_to_string` doesn’t give us the
27 opportunity to explain all the error handling, so we did it the longer way