Skip to content

Commit dd4aec0

Browse files
committed
rundb
1 parent 74d8d60 commit dd4aec0

File tree

8 files changed

+222
-136
lines changed

8 files changed

+222
-136
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ build/
2525

2626
resolve_error.sh
2727
resolve_unknown.sh
28+
.run.db

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ geo = "*"
4444
geo-types = "*"
4545
bytecount = "*"
4646
divisors = "*"
47+
rusqlite = "0.33.0"
48+
sha2 = "0.10.8"
4749

4850
[lints.clippy]
4951
pedantic = "forbid"

crates/aoc/src/args.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,21 @@ fn usage() {
101101
}
102102

103103
impl Args {
104+
/// Run a day solution, with input data read from file `input.txt`
105+
/// or the first non flag argument of the commandline.
106+
/// Display the elapsed time in the flag `--elapsed` is present.
104107
pub fn run<U, V, T>(&self, solve: T)
105108
where
106109
U: Display,
107110
V: Display,
108111
T: Fn(&str) -> (U, V),
109112
{
110-
self.run_data(solve, &self.input);
113+
let _ = self.run_data(solve, &self.input);
111114
}
112115

113-
pub fn run_data<U, V, T>(&self, solve: T, data: &str)
116+
/// Run a day solution with the given input data.
117+
/// Display the elapsed time in the flag `--elapsed` is present.
118+
pub fn run_data<U, V, T>(&self, solve: T, data: &str) -> Duration
114119
where
115120
U: Display,
116121
V: Display,
@@ -134,5 +139,7 @@ impl Args {
134139
if self.elapsed {
135140
println!("elapsed: {micros:?}");
136141
}
142+
143+
elapsed
137144
}
138145
}

crates/aoc/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use args::Args;
2-
31
mod args;
42
mod coord;
53
mod counter;
@@ -12,8 +10,12 @@ pub mod knot;
1210
pub mod math;
1311
pub mod ocr;
1412
mod square;
13+
mod unwraperror;
1514
pub mod util;
1615

16+
pub use args::Args;
17+
pub use unwraperror::DAMN;
18+
1719
pub type Coord = coord::Coord;
1820
pub type Direction = direction::Direction;
1921
pub type Grid<T> = grid::Grid<T>;
@@ -64,12 +66,12 @@ impl std::fmt::Display for Christmas {
6466
/// });
6567
/// ```
6668
#[must_use]
67-
pub fn parse_args() -> args::Args {
69+
pub fn parse_args() -> Args {
6870
Args::parse_args()
6971
}
7072

7173
#[must_use]
72-
pub fn parse_args_raw() -> args::Args {
74+
pub fn parse_args_raw() -> Args {
7375
Args::parse_args_raw()
7476
}
7577

crates/aoc/src/unwraperror.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use std::error::Error;
2+
3+
#[derive(Debug)]
4+
pub struct UnwrapError {}
5+
6+
impl std::fmt::Display for UnwrapError {
7+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8+
write!(f, "Unwrap error")
9+
}
10+
}
11+
12+
impl Error for UnwrapError {}
13+
14+
pub const DAMN: UnwrapError = UnwrapError {};

src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use std::iter::empty;
1+
pub mod rundb;
22

33
use itertools::Itertools;
4+
use std::iter::empty;
45

56
/// Get the array of all available solutions.
67
#[must_use]
@@ -54,8 +55,6 @@ macro_rules! make_year {
5455
.map_or((day, None), |(day, alt)| (day, Some(alt.to_string())));
5556
let day = day.parse().unwrap();
5657

57-
// eprintln!("=> {year} {day} {alt:?}");
58-
5958
let solve = |data: &str| {
6059
use crate::$year::$day::$day::solve;
6160
let (part1, part2) = solve(data);

0 commit comments

Comments
 (0)