1
0
Fork 0

Use expect instead of unwrap.

This commit is contained in:
Vivianne 2022-11-30 22:52:14 -08:00
parent b946b30978
commit 30aea9de13
1 changed files with 3 additions and 3 deletions

View File

@ -4,17 +4,17 @@ use std::collections::BinaryHeap;
fn main() {
let filename = "etc/p01.txt";
let file = fs::File::open(filename).unwrap();
let file = fs::File::open(filename).expect("Can't open file");
let lines = io::BufReader::new(file).lines();
let mut heap = BinaryHeap::new();
let mut cur_cals: u32 = 0;
for l in lines {
if let Ok(cals) = l.unwrap().parse::<u32>() {
if let Ok(cals) = l.expect("Can't read line.").parse::<u32>() {
cur_cals += cals;
} else {
heap.push(cur_cals);
println!("new cals: {}, max so far: {}", cur_cals, heap.peek().unwrap());
println!("new cals: {}, max so far: {}", cur_cals, heap.peek().expect("Can't peek from heap!"));
cur_cals = 0;
};
}