Trait Solution

Source
pub trait Solution<const DAY: u8>: Solver {
    type Input<'i>: RefUnwindSafe;
    type Output: Display;

    // Required method
    fn parse(puzzle: &str) -> Self::Input<'_>;

    // Provided methods
    fn part_one(input: &Self::Input<'_>) -> Self::Output { ... }
    fn part_two(input: &Self::Input<'_>) -> Self::Output { ... }
    fn run() -> Outcome<Self::Output> { ... }
}
Expand description

Implements the solution to a single Advent of Code problem.

Should be implemented on a marker struct (e.g. struct Solutions {}); see the getting started guide for more information.

Required Associated Types§

Source

type Input<'i>: RefUnwindSafe

The type representing the parsed form of the puzzle input.

The generic lifetime parameter <'i> can typically be elided; it is only necessary if the concrete type definition contains references to the puzzle input or other data.

Source

type Output: Display

The type representing the puzzle’s solution.

Required Methods§

Source

fn parse(puzzle: &str) -> Self::Input<'_>

Parse textual puzzle input into a value of type Input.

Provided Methods§

Source

fn part_one(input: &Self::Input<'_>) -> Self::Output

Compute the solution to part one of the problem.

Source

fn part_two(input: &Self::Input<'_>) -> Self::Output

Compute the solution to part two of the problem.

Source

fn run() -> Outcome<Self::Output>

Execute the solution from start to finish. This method handles wiring everything together and should not be overriden.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§