Crate aoc

Source
Expand description

A library for running Advent of Code solutions using aocli, and for parsing Advent of Code inputs.

§Examples

use aoc::Parse;

let line_1 = "first: 85, then: +192, finally: -64";
let line_2 = "first: -157, then: 4, finally: 1000";

fn parse_line(line: &str) -> [i32; 3] {
    let mut parser = line.as_parser();
    [
        parser.between("first: ", ", "),
        parser.between("then: ", ", "),
        parser.after("finally: "),
    ]
    .map(Parse::parse_uw)
}

assert_eq!(line_1.ints::<3, i32>(), [85, 192, -64]);
assert_eq!(parse_line(line_1), [85, 192, -64]);

assert_eq!(line_2.ints::<3, i32>(), [-157, 4, 1000]);
assert_eq!(parse_line(line_2), [-157, 4, 1000]);

Macros§

parts
A macro for running with aocli.

Structs§

Input
A struct for handling and parsing an input for an Advent of Code problem.
Ints
An iterator over the signed integers in a &str.
Lines
An iterator over the lines of an Input.
Parser
A struct for gradually parsing data from a string from left to right.
UInts
An iterator over the unsigned integers in a &str.

Traits§

IterUnwrap
Provides methods on iterators to reduce allocations and .unwrap() calls when success is assumed.
Parse
Provides methods on &str for parsing.

Functions§

run
The function that aoc::parts! inserts into fn main.