pub fn neighbors_diag<'a, M, R, T>(
  matrix: &'a M,
  coord: Coord,
) -> impl Iterator<Item = (&'a T, Coord)>
where
  M: Deref<Target = [R]>,
  R: 'a + Deref<Target = [T]>,
  T: 'a,
{
  let [x, y] = coord;
  let x_add_1 = x.checked_add(1);
  let x_sub_1 = x.checked_sub(1);
  let y_add_1 = y.checked_add(1);
  let y_sub_1 = y.checked_sub(1);
  let coords = [
    x_add_1.map(|x| [x, y]),
    x_sub_1.map(|x| [x, y]),
    y_add_1.map(|y| [x, y]),
    y_sub_1.map(|y| [x, y]),
    x_add_1.and_then(|x| y_add_1.map(|y| [x, y])),
    x_sub_1.and_then(|x| y_add_1.map(|y| [x, y])),
    x_add_1.and_then(|x| y_sub_1.map(|y| [x, y])),
    x_sub_1.and_then(|x| y_sub_1.map(|y| [x, y])),
  ];
  neighbors_help(matrix, coords)
}
/// Returns the neighbors (including diagonal neighbors) of `coord` in `matrix`.
/// The iterator will be at most 8 items long.
Returns the neighbors (including diagonal neighbors) of `coord` in `matrix`.
The iterator will be at most 8 items long.
Returns the neighbors ( including diagonal neighbors ) of ` coord ` in ` matrix ` . The iterator will be at most 8 items long .
pub fn neighbors_diag<'a, M, R, T>(
  matrix: &'a M,
  coord: Coord,
) -> impl Iterator<Item = (&'a T, Coord)>
where
  M: Deref<Target = [R]>,
  R: 'a + Deref<Target = [T]>,
  T: 'a,
{
  let [x, y] = coord;
  let x_add_1 = x.checked_add(1);
  let x_sub_1 = x.checked_sub(1);
  let y_add_1 = y.checked_add(1);
  let y_sub_1 = y.checked_sub(1);
  let coords = [
    x_add_1.map(|x| [x, y]),
    x_sub_1.map(|x| [x, y]),
    y_add_1.map(|y| [x, y]),
    y_sub_1.map(|y| [x, y]),
    x_add_1.and_then(|x| y_add_1.map(|y| [x, y])),
    x_sub_1.and_then(|x| y_add_1.map(|y| [x, y])),
    x_add_1.and_then(|x| y_sub_1.map(|y| [x, y])),
    x_sub_1.and_then(|x| y_sub_1.map(|y| [x, y])),
  ];
  neighbors_help(matrix, coords)
}
pub fn neighbors_diag < ' a , M , R , T > ( matrix : & ' a M , coord : Coord , ) -> impl Iterator < Item = ( & ' a T , Coord ) > where M : Deref < Target = [ R ] > , R : ' a + Deref < Target = [ T ] > , T : ' a , { let [ x , y ] = coord ; let x_add_1 = x . checked_add ( 1 ) ; let x_sub_1 = x . checked_sub ( 1 ) ; let y_add_1 = y . checked_add ( 1 ) ; let y_sub_1 = y . checked_sub ( 1 ) ; let coords = [ x_add_1 . map ( | x | [ x , y ] ) , x_sub_1 . map ( | x | [ x , y ] ) , y_add_1 . map ( | y | [ x , y ] ) , y_sub_1 . map ( | y | [ x , y ] ) , x_add_1 . and_then ( | x | y_add_1 . map ( | y | [ x , y ] ) ) , x_sub_1 . and_then ( | x | y_add_1 . map ( | y | [ x , y ] ) ) , x_add_1 . and_then ( | x | y_sub_1 . map ( | y | [ x , y ] ) ) , x_sub_1 . and_then ( | x | y_sub_1 . map ( | y | [ x , y ] ) ) , ] ; neighbors_help ( matrix , coords ) }
Returns the neighbors (including diagonal neighbors) of `coord` in `matrix`.
Returns the neighbors ( including diagonal neighbors ) of ` coord ` in ` matrix ` .
matrix
&'a M
coord
Coord
matrix
&'a M
coord
Coord