This directory contains Rust solutions for Advent of Code, organized as a Cargo workspace.
Each year is a separate crate within the workspace, depending on a shared common library.
common/: Shared utilities (input handling, geometry, BFS/Dijkstra algorithms).20XX/: Year-specific implementations.runner/: A master CLI tool to run any day from any year.
Every day is implemented as a struct that satisfies the Solution trait:
use anyhow::Result;
use aoc_common::Solution;
pub struct DayXX;
impl Solution for DayXX {
fn year(&self) -> u32 { 2023 }
fn day(&self) -> u32 { XX }
fn part1(&self, input: &str) -> Result<String> {
Ok("result".to_string())
}
fn part2(&self, input: &str) -> Result<String> {
Ok("result".to_string())
}
}
aoc_common::aoc_test!(DayXX);We use insta for snapshot testing and a custom aoc_test! macro for regression testing.
# Run all tests in the workspace
cargo test
# Run a specific year
cargo test -p aoc-rust-2023
# Run regression tests (including those ignored in CI)
cargo test -- --ignoredIn CI, heavy file-reading tests are marked as #[ignore] via the advent_of_code_ci flag to maintain pipeline speed.
- Create a new folder:
mkdir -p 20XX/src. - Initialize
Cargo.tomlwithaoc-rust-20XXname and dependency on../common. - Add the folder to
rust/Cargo.tomlworkspace members. - Implement your days in
src/dayXX.rs. - Register them in
src/lib.rsandsrc/main.rs.