[rs] Get rid of anyhow

This commit is contained in:
Joscha 2022-12-03 13:06:20 +01:00
parent 6dc0aef430
commit f0669d159f
6 changed files with 8 additions and 24 deletions

View file

@ -2,7 +2,7 @@ mod y2022;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::{fmt, fs};
use std::{fmt, fs, io};
use clap::Parser;
@ -47,7 +47,7 @@ struct Args {
files: Vec<PathBuf>,
}
fn main() -> anyhow::Result<()> {
fn main() -> io::Result<()> {
let args = Args::parse();
if args.files.is_empty() {
@ -72,9 +72,9 @@ fn main() -> anyhow::Result<()> {
println!("### Solving day {day}");
let input = fs::read_to_string(file)?;
match day {
Day::Y2022D01 => y2022::d01::solve(input)?,
Day::Y2022D02 => y2022::d02::solve(input)?,
Day::Y2022D03 => y2022::d03::solve(input)?,
Day::Y2022D01 => y2022::d01::solve(input),
Day::Y2022D02 => y2022::d02::solve(input),
Day::Y2022D03 => y2022::d03::solve(input),
}
}

View file

@ -1,4 +1,4 @@
pub fn solve(input: String) -> anyhow::Result<()> {
pub fn solve(input: String) {
let mut elves = input
.trim()
.split("\n\n")
@ -18,6 +18,4 @@ pub fn solve(input: String) -> anyhow::Result<()> {
// Part 2
let top_three = elves.iter().rev().take(3).sum::<u32>();
println!("Part 2: {top_three}");
Ok(())
}

View file

@ -70,7 +70,7 @@ fn read_round(line: &str) -> (Choice, Choice, Outcome) {
(l, rc, ro)
}
pub fn solve(input: String) -> anyhow::Result<()> {
pub fn solve(input: String) {
let matches = input
.lines()
.map(|l| read_round(l.trim()))
@ -89,6 +89,4 @@ pub fn solve(input: String) -> anyhow::Result<()> {
.map(|(l, _, r)| r.against(*l).score() + r.score())
.sum::<u32>();
println!("Part 2: {score}");
Ok(())
}

View file

@ -15,7 +15,7 @@ fn highest_score(i: u64) -> u32 {
64 - i.leading_zeros()
}
pub fn solve(input: String) -> anyhow::Result<()> {
pub fn solve(input: String) {
let backpacks = input.lines().map(|l| l.trim()).collect::<Vec<_>>();
// Part 1
@ -40,6 +40,4 @@ pub fn solve(input: String) -> anyhow::Result<()> {
.map(highest_score)
.sum::<u32>();
println!("Part 2: {score}");
Ok(())
}