gw_rust_programming_tutorial/chapter_9/
test_panic.rs

1pub fn test_painic_fn()
2{
3    //panic!("crash and burn");
4}
5
6use std::fs::File;
7
8pub fn test_panic_resume() {
9    // let f = File::open("hello.txt");
10
11    // let f = match f {
12    //     Ok(file) => file,
13    //     Err(error) => {
14    //         panic!("Problem opening the file: {:?}", error)
15    //     },
16    // };
17
18    let f = File::open("hello.txt").unwrap();
19}
20
21
22use std::io;
23use std::io::Read;
24
25pub fn read_username_from_file() -> Result<String, io::Error> {
26    let f = File::open("hello.txt");
27
28    let mut f = match f {
29        Ok(file) => file,
30        Err(e) =>{println!("ssss111"); return Err(e)},
31    };
32
33    let mut s = String::new();
34    match f.read_to_string(&mut s) {
35        Ok(_) => Ok(s),
36        Err(e) => {
37            println!("sssss");
38            Err(e)},
39    }
40}