summaryrefslogtreecommitdiffstats
path: root/src/doc/book/listings/ch09-error-handling/listing-09-08/src/main.rs
blob: c3c6e23efcc2641ac26b7c9f5e841369883bf8a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// ANCHOR: here
use std::fs::File;
use std::io;
use std::io::Read;

fn read_username_from_file() -> Result<String, io::Error> {
    let mut username = String::new();

    File::open("hello.txt")?.read_to_string(&mut username)?;

    Ok(username)
}
// ANCHOR_END: here

fn main() {
    let username = read_username_from_file().expect("Unable to get username");
}