]> git.proxmox.com Git - rustc.git/blob - src/doc/book/listings/ch09-error-handling/no-listing-03-closures/src/main.rs
New upstream version 1.43.0+dfsg1
[rustc.git] / src / doc / book / listings / ch09-error-handling / no-listing-03-closures / src / main.rs
1 use std::fs::File;
2 use std::io::ErrorKind;
3
4 fn main() {
5 let f = File::open("hello.txt").unwrap_or_else(|error| {
6 if error.kind() == ErrorKind::NotFound {
7 File::create("hello.txt").unwrap_or_else(|error| {
8 panic!("Problem creating the file: {:?}", error);
9 })
10 } else {
11 panic!("Problem opening the file: {:?}", error);
12 }
13 });
14 }