aoc-auto

Crates.ioaoc-auto
lib.rsaoc-auto
version0.1.0
sourcesrc
created_at2023-12-03 23:25:23.762126
updated_at2023-12-03 23:25:23.762126
descriptionAutomatically imports your solutions to Advent of Code challenges for easy running.
homepage
repositoryhttps://github.com/AlexanderReaper7/aoc-auto
max_upload_size
id1057128
size9,004
Alexander Öberg (AlexanderReaper7)

documentation

README

aoc-auto

Simplifies and speeds up the process of starting a new advent of code challenge.

This is a build script that generates files that automatically generates rust files that imports you 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

Usage

Installation

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();
}

Project Structure

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!()
}

Running

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));
}

TODO

  • CLI Tool to create template file into the selected year and day.
    • Also automatically fetch the day´s title and URL from the AOC website and paste it into the files description.
Commit count: 7

cargo fmt