Trait advent_of_code_traits::Solution[][src]

pub trait Solution<const Day: u32>: ParseEachInput<Day, Part1> + ParseEachInput<Day, Part2> {
    type Part1Output: Display;
    type Part2Output: Display;
    fn part1(input: &Self::Parsed) -> Self::Part1Output;
fn part2(input: &Self::Parsed) -> Self::Part2Output; fn run(input: &str) { ... } }

Implement the Solution trait for each day of Advent of Code for your struct(s).

Each day is a unique implementation, implement each on any struct you like.

Example

pub struct AdventOfCode2020;

impl Solution<Day1> for AdventOfCode2020 {
    type Part1Output = u32;
    type Part2Output = u32;
    fn part1(input: &Vec<u32>) -> u32 {
        // your solution to part1 here...
    }

    fn part2(input: &Vec<u32>) -> u32 {
        // your solution to part2 here...
    }
}

Associated Types

type Part1Output: Display[src]

The type output by Solution::part1 This must implement Display so that we can print it

type Part2Output: Display[src]

The type output by Solution::part2 This must implement Display so that we can print it

Loading content...

Required methods

fn part1(input: &Self::Parsed) -> Self::Part1Output[src]

fn part2(input: &Self::Parsed) -> Self::Part2Output[src]

Loading content...

Provided methods

fn run(input: &str)[src]

The default implementation of run will:

  • parse your input for each part
  • call part1 and part2 with their parsed inputs.
  • Print a short summary to display the output

You can provide your own implementation of this method to change this deafult behaviour.

Example

pub struct AdventOfCode2020;

impl Solution<Day1> for AdventOfCode2020 {
    type Part1Output = u32;
    type Part2Output = u32;
    fn part1(input: &Vec<u32>) -> u32 {
        // your solution to part1 here...
    }

    fn part2(input: &Vec<u32>) -> u32 {
        // your solution to part2 here...
    }

    fn run(input: &str) {
        let shared_parsed_input = <Self as ParseInput<Day1>>::parse_input(input);

        let part1_output = Self::part1(&shared_parsed_input);
        let part2_output = Self::part2(&shared_parsed_input);

        // maybe you prefer a single line output?
        println!("Day{}: {} - {}", Day1, part1_output, part2_output);
    }

}
Loading content...

Implementors

Loading content...