Function advent_of_code_2021::day_2::parse_line[−][src]

fn parse_line(line: &str) -> (Direction, isize)
Expand description

Parses a line in the format (forward|up|down) \d+ into the internal representation Instruction. Will panic if the provided line does not match the expected format.

Example from puzzle specification

assert_eq!(parse_line("forward 5"), (FORWARD, 5));
assert_eq!(parse_line("down 5"),    (DOWN,    5));
assert_eq!(parse_line("forward 8"), (FORWARD, 8));
assert_eq!(parse_line("up 3"),      (UP,      3));
assert_eq!(parse_line("down 8"),    (DOWN,    8));
assert_eq!(parse_line("forward 2"), (FORWARD, 2));