From 32bacbeb1de264808f9a2fd808250682a0bc26ef Mon Sep 17 00:00:00 2001 From: Bram Date: Mon, 1 Dec 2025 17:13:18 +0100 Subject: [PATCH] Add args to Rust program to run individual days --- bram/rust/src/lib.rs | 2 +- bram/rust/src/main.rs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/bram/rust/src/lib.rs b/bram/rust/src/lib.rs index 53eca85..38a5511 100644 --- a/bram/rust/src/lib.rs +++ b/bram/rust/src/lib.rs @@ -15,7 +15,7 @@ use std::time::Duration; use crate::utils::read_from_file; use crate::utils::diagnostics; -type DailyOutput = ( u128, u128, Duration ); +pub type DailyOutput = ( u128, u128, Duration ); pub use crate::utils::diagnostics::AdventOfCode; diff --git a/bram/rust/src/main.rs b/bram/rust/src/main.rs index 094d476..0810a55 100644 --- a/bram/rust/src/main.rs +++ b/bram/rust/src/main.rs @@ -1,4 +1,31 @@ fn main() { + let args: Vec = std::env::args().collect(); + + if args.len() > 1 { + let day : Option = args[1].parse().ok(); + + match day { + Some(1) => run_day(aoc2025::day_01), + // Some(2) => run_day(aoc2025::day_02), + // Some(3) => run_day(aoc2025::day_03), + // Some(4) => run_day(aoc2025::day_04), + // Some(5) => run_day(aoc2025::day_05), + // Some(6) => run_day(aoc2025::day_06), + // Some(7) => run_day(aoc2025::day_07), + // Some(8) => run_day(aoc2025::day_08), + // Some(9) => run_day(aoc2025::day_09), + // Some(10) => run_day(aoc2025::day_10), + // Some(11) => run_day(aoc2025::day_11), + // Some(12) => run_day(aoc2025::day_12), + Some(_) => run_all_days(), + None => run_all_days(), + } + } else { + run_all_days(); + } +} + +fn run_all_days() { let mut aoc = aoc2025::AdventOfCode::new(); aoc.insert(1, aoc2025::day_01()); @@ -16,3 +43,10 @@ fn main() { aoc.show_diagnostics(); } + +fn run_day(day : fn() -> aoc2025::DailyOutput) { + let (p1, p2, _) = day(); + + println!("Part 1: {}", p1); + println!("Part 2: {}", p2); +}