[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

7
rs/Cargo.lock generated
View file

@ -6,16 +6,9 @@ version = 3
name = "advent-of-code" name = "advent-of-code"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow",
"clap", "clap",
] ]
[[package]]
name = "anyhow"
version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.3.2" version = "1.3.2"

View file

@ -3,8 +3,5 @@ name = "advent-of-code"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
anyhow = "1.0.66"
clap = { version = "4.0.29", features = ["derive", "deprecated"] } clap = { version = "4.0.29", features = ["derive", "deprecated"] }

View file

@ -2,7 +2,7 @@ mod y2022;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::str::FromStr; use std::str::FromStr;
use std::{fmt, fs}; use std::{fmt, fs, io};
use clap::Parser; use clap::Parser;
@ -47,7 +47,7 @@ struct Args {
files: Vec<PathBuf>, files: Vec<PathBuf>,
} }
fn main() -> anyhow::Result<()> { fn main() -> io::Result<()> {
let args = Args::parse(); let args = Args::parse();
if args.files.is_empty() { if args.files.is_empty() {
@ -72,9 +72,9 @@ fn main() -> anyhow::Result<()> {
println!("### Solving day {day}"); println!("### Solving day {day}");
let input = fs::read_to_string(file)?; let input = fs::read_to_string(file)?;
match day { match day {
Day::Y2022D01 => y2022::d01::solve(input)?, Day::Y2022D01 => y2022::d01::solve(input),
Day::Y2022D02 => y2022::d02::solve(input)?, Day::Y2022D02 => y2022::d02::solve(input),
Day::Y2022D03 => y2022::d03::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 let mut elves = input
.trim() .trim()
.split("\n\n") .split("\n\n")
@ -18,6 +18,4 @@ pub fn solve(input: String) -> anyhow::Result<()> {
// Part 2 // Part 2
let top_three = elves.iter().rev().take(3).sum::<u32>(); let top_three = elves.iter().rev().take(3).sum::<u32>();
println!("Part 2: {top_three}"); println!("Part 2: {top_three}");
Ok(())
} }

View file

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

View file

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