mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-05-01 10:49:12 +08:00
20 lines
555 B
Rust
Executable File
20 lines
555 B
Rust
Executable File
use std::fs::File;
|
|
use std::io::ErrorKind;
|
|
|
|
fn main() {
|
|
let greeting_file_result = File::open("hello.txt");
|
|
|
|
let greeting_file = match greeting_file_result {
|
|
Ok(file) => file,
|
|
Err(error) => match error.kind() {
|
|
ErrorKind::NotFound => match File::create("hello.txt") {
|
|
Ok(fc) => fc,
|
|
Err(e) => panic!("Problem creating the file: {:?}", e),
|
|
},
|
|
other_error => {
|
|
panic!("Problem opening the file: {:?}", other_error);
|
|
}
|
|
},
|
|
};
|
|
}
|