Created
March 4, 2021 02:01
-
-
Save cindywu/0f751a12270c39340d74892a6b3900aa to your computer and use it in GitHub Desktop.
variant of error thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::fs::File; | |
| use std::io::ErrorKind; | |
| fn main() { | |
| let _f = File::open("hello.txt").unwrap_or_else(|error| { | |
| if error.kind() == ErrorKind::NotFound { | |
| File::create("hello.txt").unwrap_or_else(|error| { | |
| panic!("Problem creating the file: {:?}", error); | |
| }) | |
| } else { | |
| panic!("Problem opening the file: {:?}", error); | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment