]> git.proxmox.com Git - rustc.git/blob - src/doc/book/listings/ch09-error-handling/listing-09-08/src/main.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / doc / book / listings / ch09-error-handling / listing-09-08 / src / main.rs
1 // ANCHOR: here
2 use std::fs::File;
3 use std::io;
4 use std::io::Read;
5
6 fn read_username_from_file() -> Result<String, io::Error> {
7 let mut username = String::new();
8
9 File::open("hello.txt")?.read_to_string(&mut username)?;
10
11 Ok(username)
12 }
13 // ANCHOR_END: here
14
15 fn main() {
16 let username = read_username_from_file().expect("Unable to get username");
17 }