Refactor code to be slightly more idiomatic, maybe

This commit is contained in:
Anna Rose 2024-02-14 19:10:53 +00:00
parent 4bda83476c
commit 577da4ab52
2 changed files with 4 additions and 3 deletions

View File

@ -7,12 +7,12 @@ fn read_lines(filename: &str) -> io::Result<io::Lines<io::BufReader<File>>> {
Ok(io::BufReader::new(file).lines())
}
fn main() {
fn main() -> Result<(), io::Error> {
let mut max = 0;
let mut current = 0;
for line in read_lines("input.txt").unwrap() {
let text = line.unwrap();
for line in read_lines("input.txt")? {
let text = line?;
current = match text.parse::<i32>() {
Ok(value) => current + value,
Err(_) => {
@ -23,4 +23,5 @@ fn main() {
}
println!("{}", max);
Ok(())
}