Refactor code to be slightly more idiomatic, maybe
This commit is contained in:
parent
4bda83476c
commit
577da4ab52
|
@ -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(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user