hs-rust-learn 0.1.0

hs's rust test learn
Documentation
use std::{fs::File, io::Read};

fn read_file (file_path: &str) -> Result<String, std::io::Error> {
    let mut s = String::new();
    File::open(file_path)?.read_to_string(&mut s)?;
    // println!("{}", s);
    Ok(s)
}

fn max(list: &[i32]) -> i32 {
    let mut max = list[0];
    for &item in list {
        if item > max {
            max = item;
        }
    }
    max
}

fn main () {
    // panic!("crash and burn");
    // let v = vec![1, 2, 3];
    // let first = &v[9];
    // println!("{}", first);

    let f = File::open("src/string1.rs");
    let file = match f {
        Ok(file) => file,
        Err(error) => match error.kind() {
            std::io::ErrorKind::NotFound => match File::create("src/string1.rs") {
                Ok(fc) => fc,
                Err(e) => panic!("Problem creating the file: {:?}", e),
            },
            other_error => panic!("Problem opening the file: {:?}", other_error),
        },
    };
    println!("{:?}", file);

    let s = read_file("src/struct.rs");
    println!("{:?}", s.unwrap());

    println("{}", max(vec![]));
}