Function utils::grid::from_str

source ·
pub fn from_str<T>(
    input: &str,
    func: impl FnMut(u8) -> Option<T>,
) -> Result<(usize, usize, Vec<T>), InputError>
Expand description

Parse 2D grid.

This function assumes that one byte represents each item in the grid.

Returns (number of rows, number of columns, data) on success.

§Examples

assert_eq!(
    from_str("##.#\n#..#\n#.##", |c| match c {
        b'#' => Some(true),
        b'.' => Some(false),
        _ => None,
    }).unwrap(),
    (3, 4, vec![
        true, true, false, true,
        true, false, false, true,
        true, false, true, true,
    ]),
);