Skip to content

Instantly share code, notes, and snippets.

@cindywu
Created March 4, 2021 02:01
Show Gist options
  • Select an option

  • Save cindywu/0f751a12270c39340d74892a6b3900aa to your computer and use it in GitHub Desktop.

Select an option

Save cindywu/0f751a12270c39340d74892a6b3900aa to your computer and use it in GitHub Desktop.
variant of error thing
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