Crate aoc_star

Crate aoc_star 

Source
Expand description

§AOC Star

aoc-star is a small library and CLI helper to organize and run your Advent of Code solutions.

It provides:

  • An attribute macro #[aoc_star::star(...)] to register solution functions for a given day, part, and optional year.
  • A tiny “runner” that looks up the appropriate solution based on CLI arguments and executes it, wiring up input loading and (optionally) answer submission via aoc-client.

§Quick example

Add aoc-star to your Cargo.toml:

[dependencies]
aoc-star = "0.1"

Then in your binary crate (for example src/bin/aoc.rs):

use aoc_star::star;

#[star(day = 1, part = 1, year = 2024)]
fn day1_part1(input: String) -> String {
    // Solve the puzzle here using the contents of `input`
    input.lines().count().to_string()
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    aoc_star::run()
}

Running this binary like

cargo run -- --day 1 --part 1 --year 2024

will look up the registered solution for day 1, part 1, year 2024, fetch the input (or read it from a file if you pass --input-file), and print the resulting answer.

§Features

  • aoc-client (optional): enable remote input fetching and answer submission using the aoc-client crate. When disabled you must always provide an --input-file.
  • test-helpers: re-exports some internals (CommandArgument and run_with_result) to make integration testing easier.

! ### star macro

The #[star(day = X, part = Y, year = Z)] attribute macro registers the annotated function as the solution for the specified day, part, and optional year. The function must have the signature fn(String) -> String, where the input String contains the puzzle input, and the returned String is the answer.

If the year parameter is omitted, the solution is considered year-agnostic and will be used for any year that does not halve a more specific solution.

§CLI arguments

The run function parses the following command line arguments:

  • --day <DAY>: The Advent of Code day (1–25).
  • --part <PART>: The puzzle part (usually 1 or 2).
  • --year <YEAR>: The Advent of Code year (e.g., 2024). Defaults to the current year if not provided.
  • --input-file <FILE>: Path to a file containing the puzzle input. This argument is required if the aoc-client feature is not enabled.
  • --publish: If provided and the aoc-client feature is enabled, the computed answer will be submitted to Advent of Code.

The default year is either the one on the config file or the current year. The config contains the session cookie needed to fetch inputs and publish answers and the default year. If not present, the config file can be created by running this command with the --setup flag. It will be located at $XDG_CONFIG_HOME/aoc-star/config.toml which in linux systems usually resolves to ~/.config/aoc-star/config.toml.

§License

Re-exports§

pub use inventory;

Structs§

AocEntry
A registered Advent of Code solution.

Functions§

run
Run the Advent of Code solution based on command line arguments.

Attribute Macros§

star
Attribute macro to mark a function as an Advent of Code solution