fn split_to_grids(input: &str) -> Result<Vec<Vec<Grid>>, Error> {
    let raw_lines: Vec<&str> = input.lines().collect();
    let raw_rows = raw_lines.len();
    if raw_rows == 0 {
        return Ok(vec![]);
    }
    if raw_rows % GRID_ROWS != 0 {
        return Err(Error::InvalidRowCount(raw_rows));
    }
    let raw_cols = raw_lines[0].len();
    if raw_cols % GRID_COLS != 0 {
        return Err(Error::InvalidColumnCount(raw_cols));
    }
    if raw_lines.iter().any(|l| l.len() != raw_cols) {
        return Err(Error::ColumnCountInconsistent);
    }

    Ok(raw_lines
        .chunks(GRID_ROWS)
        .into_iter()
        .map(
            // process one "logical line",
            // which are GRID_ROWS lines of raw_lines
            |digits_line: &[&str]| -> Vec<Grid> {
                // separate one logical line into Grids.
                (0..raw_cols)
                    .step_by(GRID_COLS)
                    .map(|i| {
                        Grid(
                            digits_line
                                .iter()
                                .map(|l: &&str| &l[i..i + GRID_COLS])
                                .collect::<Vec<&str>>(),
                        )
                    })
                    .collect()
            },
        )
        .collect())
}
/// Splits a raw input string into 2D Vec of Grids.
Splits a raw input string into 2D Vec of Grids.
Splits a raw input string into 2D Vec of Grids .
fn split_to_grids(input: &str) -> Result<Vec<Vec<Grid>>, Error> {
    let raw_lines: Vec<&str> = input.lines().collect();
    let raw_rows = raw_lines.len();
    if raw_rows == 0 {
        return Ok(vec![]);
    }
    if raw_rows % GRID_ROWS != 0 {
        return Err(Error::InvalidRowCount(raw_rows));
    }
    let raw_cols = raw_lines[0].len();
    if raw_cols % GRID_COLS != 0 {
        return Err(Error::InvalidColumnCount(raw_cols));
    }
    if raw_lines.iter().any(|l| l.len() != raw_cols) {
        return Err(Error::ColumnCountInconsistent);
    }
    Ok(raw_lines
        .chunks(GRID_ROWS)
        .into_iter()
        .map(
            // process one "logical line",
            // which are GRID_ROWS lines of raw_lines
            |digits_line: &[&str]| -> Vec<Grid> {
                // separate one logical line into Grids.
                (0..raw_cols)
                    .step_by(GRID_COLS)
                    .map(|i| {
                        Grid(
                            digits_line
                                .iter()
                                .map(|l: &&str| &l[i..i + GRID_COLS])
                                .collect::<Vec<&str>>(),
                        )
                    })
                    .collect()
            },
        )
        .collect())
}
fn split_to_grids ( input : & str ) -> Result < Vec < Vec < Grid > > , Error > { let raw_lines : Vec < & str > = input . lines ( ) . collect ( ) ; let raw_rows = raw_lines . len ( ) ; if raw_rows == 0 { return Ok ( vec ! [ ] ) ; } if raw_rows % GRID_ROWS != 0 { return Err ( Error :: InvalidRowCount ( raw_rows ) ) ; } let raw_cols = raw_lines [ 0 ] . len ( ) ; if raw_cols % GRID_COLS != 0 { return Err ( Error :: InvalidColumnCount ( raw_cols ) ) ; } if raw_lines . iter ( ) . any ( | l | l . len ( ) != raw_cols ) { return Err ( Error :: ColumnCountInconsistent ) ; } Ok ( raw_lines . chunks ( GRID_ROWS ) . into_iter ( ) . map ( // process one "logical line", // which are GRID_ROWS lines of raw_lines | digits_line : & [ & str ] | -> Vec < Grid > { // separate one logical line into Grids. ( 0 .. raw_cols ) . step_by ( GRID_COLS ) . map ( | i | { Grid ( digits_line . iter ( ) . map ( | l : & & str | & l [ i .. i + GRID_COLS ] ) . collect :: < Vec < & str > > ( ) , ) } ) . collect ( ) } , ) . collect ( ) ) }
Splits a raw input string into 2D Vec of Grids.
Splits a raw input string into 2D Vec of Grids .
input
&str
input
&str