| Crates.io | aoc-auto |
| lib.rs | aoc-auto |
| version | 0.2.0 |
| created_at | 2023-12-03 23:25:23.762126+00 |
| updated_at | 2025-05-25 02:15:12.792746+00 |
| description | Automatically imports your solutions to Advent of Code challenges for easy running. |
| homepage | |
| repository | https://github.com/AlexanderReaper7/aoc-auto |
| max_upload_size | |
| id | 1057128 |
| size | 61,851 |
This is a build script that automatically generates rust files that imports your solutions for each of the year/day/part according to a predetermined project structure.
You can see how I use this at https://github.com/AlexanderReaper7/advent-of-code-rs
Run the cargo add aoc-auto --build to add it to your project´s build dependencies.
Then add the following to your build.rs file:
// build.rs
use aoc_auto::aoc_auto;
fn main() {
aoc_auto();
}
The project structure you need to use folders named y{year} containing files named d{day}.rs for each day of that year´s AOC challenge.
An example of this is as follows:
├── Cargo.toml
├── build.rs
└── src
├── y2023
│ ├── d1.rs
│ └── d2.rs
├── y2024
│ ├── d1.rs
│ └── d2.rs
└── main.rs
This will turn into the following:
├── Cargo.toml
├── build.rs
└── src
├── y2023
│ ├── d1.rs
│ ├── d2.rs
│ └── mod.rs
├── y2024
│ ├── d1.rs
│ ├── d2.rs
│ └── mod.rs
├── main.rs
└── auto_import.rs
The d1.rs (and any other day) must contain two functions: part1 and part2 that take a String and return a String.
// src/y2023/d1.rs
pub fn part1(input: String) -> String {
unimplemented!()
}
pub fn part2(input: String) -> String {
unimplemented!()
}
In your main.rs file, you can now import the generated auto_import file and use the select_function function to select your chosen solution.
// src/main.rs
mod auto_import;
fn main() {
// Some example input
let input = "challenge input"
// Select the function for year 2023, day 1, part 1
let function = auto_import::select_function(2023, 1, 1).unwrap();
// Call the function with the input and print the result
println!("{}", function(input));
}