aochelpers

Function parse_number_grid

Source
pub fn parse_number_grid<T, V>(data: &str) -> HashMap<Coordinate<T>, V>
where T: Integer + Copy + TryFrom<usize> + Hash, V: FromStr, <V as FromStr>::Err: Debug,
Expand description

Parses a grid of digits in the form of a string to a HashMap<Coordinate, T>

The Y value represents the line number, so increases down the page.

Example usage:

parse_number_grid::<i32, i32>("12\n34")

will return a HashMap<Coordinate<i32>, i32> equivalent to:

HashMap::<Coordinate<usize>,i32>::from([
    (Coordinate{x:0, y:0}, 1),
    (Coordinate{x:1, y:0}, 2),
    (Coordinate{x:0, y:1}, 3),
    (Coordinate{x:1, y:2}, 4)
]);