]> git.proxmox.com Git - rustc.git/blob - src/doc/book/listings/ch09-error-handling/listing-09-05/src/main.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / doc / book / listings / ch09-error-handling / listing-09-05 / src / main.rs
1 use std::fs::File;
2 use std::io::ErrorKind;
3
4 fn main() {
5 let greeting_file_result = File::open("hello.txt");
6
7 let greeting_file = match greeting_file_result {
8 Ok(file) => file,
9 Err(error) => match error.kind() {
10 ErrorKind::NotFound => match File::create("hello.txt") {
11 Ok(fc) => fc,
12 Err(e) => panic!("Problem creating the file: {:?}", e),
13 },
14 other_error => {
15 panic!("Problem opening the file: {:?}", other_error);
16 }
17 },
18 };
19 }