summaryrefslogtreecommitdiffstats
path: root/src/doc/book/listings/ch09-error-handling/listing-09-07/src/main.rs
blob: f4564f670dcb642b7878607a365552592e90f697 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 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_file = File::open("hello.txt")?;
    let mut username = String::new();
    username_file.read_to_string(&mut username)?;
    Ok(username)
}
// ANCHOR_END: here

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