Use expect instead of unwrap.
This commit is contained in:
parent
b946b30978
commit
30aea9de13
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue