From d5c85d4a175448ae8c1815ec357d8d4dfccec3cf Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Thu, 25 Nov 2021 16:49:52 +0100 Subject: [PATCH] 2021: setup boilerplate --- Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 2 +- aoc2021/Cargo.toml | 18 ++++++++++++++++++ aoc2021/aoc2021_bench/Cargo.toml | 17 +++++++++++++++++ aoc2021/aoc2021_bench/benches/aoc2021_bench.rs | 14 ++++++++++++++ aoc2021/input/day00.txt | 1 + aoc2021/src/day00.rs | 17 +++++++++++++++++ aoc2021/src/lib.rs | 3 +++ aoc2021/src/main.rs | 11 +++++++++++ 9 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 aoc2021/Cargo.toml create mode 100644 aoc2021/aoc2021_bench/Cargo.toml create mode 100644 aoc2021/aoc2021_bench/benches/aoc2021_bench.rs create mode 100644 aoc2021/input/day00.txt create mode 100644 aoc2021/src/day00.rs create mode 100644 aoc2021/src/lib.rs create mode 100644 aoc2021/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 1f1b772..acee5e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,6 +82,22 @@ dependencies = [ "criterion", ] +[[package]] +name = "aoc2021" +version = "0.1.0" +dependencies = [ + "anyhow", + "aoc", +] + +[[package]] +name = "aoc2021_bench" +version = "0.1.0" +dependencies = [ + "aoc2021", + "criterion", +] + [[package]] name = "arrayvec" version = "0.5.2" diff --git a/Cargo.toml b/Cargo.toml index 7ab5e2e..1fddce8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [workspace] members = ["aoc*", "aoc*/aoc*_bench"] -default-members = ["aoc2020"] +default-members = ["aoc2021"] [profile.release] debug = true diff --git a/aoc2021/Cargo.toml b/aoc2021/Cargo.toml new file mode 100644 index 0000000..b336e63 --- /dev/null +++ b/aoc2021/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "aoc2021" +version = "0.1.0" +authors = ["Antoine Martin "] +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +aoc = { path = "../aoc" } +anyhow = "1.0" + +[lib] +path = "src/lib.rs" + +[[bin]] +name = "aoc2021" +path = "src/main.rs" diff --git a/aoc2021/aoc2021_bench/Cargo.toml b/aoc2021/aoc2021_bench/Cargo.toml new file mode 100644 index 0000000..d8f7503 --- /dev/null +++ b/aoc2021/aoc2021_bench/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "aoc2021_bench" +version = "0.1.0" +authors = ["Antoine Martin "] +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +aoc2021 = { path = "../" } + +[dev-dependencies] +criterion = "0.3" + +[[bench]] +name = "aoc2021_bench" +harness = false diff --git a/aoc2021/aoc2021_bench/benches/aoc2021_bench.rs b/aoc2021/aoc2021_bench/benches/aoc2021_bench.rs new file mode 100644 index 0000000..bfd8973 --- /dev/null +++ b/aoc2021/aoc2021_bench/benches/aoc2021_bench.rs @@ -0,0 +1,14 @@ +use criterion::{criterion_group, criterion_main, Criterion}; + +use aoc2021::day00; + +fn aoc2021_all(c: &mut Criterion) { + c.bench_function("day00", |b| b.iter(|| day00::run().unwrap())); +} + +criterion_group! { + name = all_days; + config = Criterion::default().sample_size(200); + targets = aoc2021_all +} +criterion_main!(all_days); diff --git a/aoc2021/input/day00.txt b/aoc2021/input/day00.txt new file mode 100644 index 0000000..cd08755 --- /dev/null +++ b/aoc2021/input/day00.txt @@ -0,0 +1 @@ +Hello world! diff --git a/aoc2021/src/day00.rs b/aoc2021/src/day00.rs new file mode 100644 index 0000000..3e48bd2 --- /dev/null +++ b/aoc2021/src/day00.rs @@ -0,0 +1,17 @@ +use std::fmt::Write; + +use anyhow::Result; + +const INPUT: &str = include_str!("../input/day00.txt"); + +pub fn run() -> Result { + let mut res = String::with_capacity(128); + + writeln!(res, "part 1: {}", part1(INPUT)?)?; + + Ok(res) +} + +fn part1(input: &str) -> Result<&str> { + Ok(input) +} diff --git a/aoc2021/src/lib.rs b/aoc2021/src/lib.rs new file mode 100644 index 0000000..7b7f8e8 --- /dev/null +++ b/aoc2021/src/lib.rs @@ -0,0 +1,3 @@ +#![warn(clippy::explicit_iter_loop, clippy::redundant_closure_for_method_calls)] + +pub mod day00; diff --git a/aoc2021/src/main.rs b/aoc2021/src/main.rs new file mode 100644 index 0000000..6bfb61e --- /dev/null +++ b/aoc2021/src/main.rs @@ -0,0 +1,11 @@ +use anyhow::Result; + +use aoc::DayFunc; + +use aoc2021::day00; + +fn main() -> Result<()> { + let days: &[DayFunc] = &[day00::run]; + + aoc::run(days) +}