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)?;
Ok(s)
}
fn max(list: &[i32]) -> i32 {
let mut max = list[0];
for &item in list {
if item > max {
max = item;
}
}
max
}
fn main () {
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![]));
}